File tree 4 files changed +62
-1
lines changed
core/src/main/java/ch/ergon/adam/core/db/schema
integration-test/src/test/java/ch/ergon/adam/integrationtest/postgresql
jooq/src/main/java/ch/ergon/adam/jooq
4 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ public enum DataType {
28
28
DATE ,
29
29
TIMESTAMP ,
30
30
TIME ,
31
+ INTERVALYEARTOSECOND ,
31
32
INTERVALYEARTOMONTH ,
32
33
INTERVALDAYTOSECOND ,
33
34
LOCALDATE ,
Original file line number Diff line number Diff line change
1
+ package ch .ergon .adam .integrationtest .postgresql ;
2
+
3
+ import ch .ergon .adam .integrationtest .AbstractDbTestBase ;
4
+ import ch .ergon .adam .integrationtest .DummySink ;
5
+ import ch .ergon .adam .core .db .schema .Schema ;
6
+ import org .junit .jupiter .api .Test ;
7
+
8
+ import static org .hamcrest .CoreMatchers .is ;
9
+ import static org .hamcrest .MatcherAssert .assertThat ;
10
+
11
+ public class PostgreSqlIntervalFieldTest extends AbstractDbTestBase {
12
+
13
+ public PostgreSqlIntervalFieldTest () {
14
+ super (new PostgreSqlTestDbUrlProvider ());
15
+ }
16
+
17
+ private static final String YML = "---\n " +
18
+ "name: \" test_table\" \n " +
19
+ "fields:\n " +
20
+ "- name: \" duration\" \n " +
21
+ " dataType: \" INTERVALYEARTOSECOND\" \n " +
22
+ "--- []\n " +
23
+ "--- []\n " ;
24
+
25
+ private static final String CREATE_TABLE_SQL =
26
+ "create table test_table (" +
27
+ "duration interval not null" +
28
+ ")" ;
29
+
30
+ @ Test
31
+ public void testCreateTableToYml () throws Exception {
32
+ getSourceDbConnection ().createStatement ().execute (CREATE_TABLE_SQL );
33
+ sourceToTarget ();
34
+ DummySink dummySink = targetToDummy ();
35
+ Schema schema = dummySink .getTargetSchema ();
36
+ migrateTargetWithSchema (schema );
37
+ String yml = targetToYml ();
38
+ assertThat (yml , is (YML ));
39
+ }
40
+
41
+ }
Original file line number Diff line number Diff line change @@ -410,6 +410,9 @@ protected DataType<?> mapRawType(ch.ergon.adam.core.db.schema.DataType type) {
410
410
case TIME :
411
411
jooqType = SQLDataType .TIME ;
412
412
break ;
413
+ case INTERVALYEARTOSECOND :
414
+ jooqType = SQLDataType .INTERVAL ;
415
+ break ;
413
416
case INTERVALYEARTOMONTH :
414
417
jooqType = SQLDataType .INTERVALYEARTOMONTH ;
415
418
break ;
Original file line number Diff line number Diff line change 9
9
import ch .ergon .adam .core .db .schema .Table ;
10
10
import org .jooq .*;
11
11
import org .jooq .impl .DSL ;
12
+ import org .jooq .types .DayToSecond ;
13
+ import org .jooq .types .YearToMonth ;
14
+ import org .jooq .types .YearToSecond ;
12
15
13
16
import java .sql .Connection ;
14
17
import java .sql .DriverManager ;
@@ -193,7 +196,20 @@ protected boolean isSequence(org.jooq.Field<?> jooqField) {
193
196
}
194
197
195
198
protected DataType mapDataTypeFromJooq (org .jooq .Field <?> jooqField ) {
196
- String typeName = jooqField .getDataType ().getSQLDataType ().getTypeName ();
199
+ org .jooq .DataType <?> sqlDataType = jooqField .getDataType ().getSQLDataType ();
200
+ if (sqlDataType .isInterval ()) {
201
+ Class <?> type = sqlDataType .getType ();
202
+ if (type .equals (YearToSecond .class )) {
203
+ return DataType .INTERVALYEARTOSECOND ;
204
+ } else if (type .equals (YearToMonth .class )) {
205
+ return DataType .INTERVALYEARTOMONTH ;
206
+ } else if (type .equals (DayToSecond .class )) {
207
+ return DataType .INTERVALDAYTOSECOND ;
208
+ } else {
209
+ throw new RuntimeException ("Unsupported interval type [" + type .getName () + "]" );
210
+ }
211
+ }
212
+ String typeName = sqlDataType .getTypeName ();
197
213
try {
198
214
return DataType .valueOf (typeName .toUpperCase ().replace (" " , "" ));
199
215
} catch (IllegalArgumentException e ) {
You can’t perform that action at this time.
0 commit comments