Skip to content

Commit 2d1a6a5

Browse files
Timetsamp
1 parent 150b0ba commit 2d1a6a5

File tree

7 files changed

+73
-10
lines changed

7 files changed

+73
-10
lines changed

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleConnector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ protected DBConnectorPath getDBConnectorPath(String path) {
114114
@Override
115115
protected SchemaReader getSchemaReader(String sessionID) {
116116
return new OracleSourceSchemaReader(sessionID, config.getTreatAsOldTimestamp(),
117-
config.getTreatPrecisionlessNumAsDeci());
117+
config.getTreatPrecisionlessNumAsDeci(),
118+
config.getTreatAsTimestampForLocalTimeZone());
118119
}
119120

120121
@Override

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleConnectorConfig.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ public OracleConnectorConfig(String host, int port, String user, String password
4242
public OracleConnectorConfig(String host, int port, String user, String password, String jdbcPluginName,
4343
String connectionArguments, String connectionType, String database) {
4444
this(host, port, user, password, jdbcPluginName, connectionArguments, connectionType, database, null, null, null,
45-
null);
45+
null, null);
4646
}
4747

4848
public OracleConnectorConfig(String host, int port, String user, String password, String jdbcPluginName,
4949
String connectionArguments, String connectionType, String database,
5050
String role, Boolean useSSL, @Nullable Boolean treatAsOldTimestamp,
51-
@Nullable Boolean treatPrecisionlessNumAsDeci) {
51+
@Nullable Boolean treatPrecisionlessNumAsDeci,
52+
@Nullable Boolean treatAsTimestampForLocalTimeZone) {
5253

5354
this.host = host;
5455
this.port = port;
@@ -62,6 +63,7 @@ public OracleConnectorConfig(String host, int port, String user, String password
6263
this.useSSL = useSSL;
6364
this.treatAsOldTimestamp = treatAsOldTimestamp;
6465
this.treatPrecisionlessNumAsDeci = treatPrecisionlessNumAsDeci;
66+
this.treatAsTimestampForLocalTimeZone = treatAsTimestampForLocalTimeZone;
6567
}
6668

6769
@Override
@@ -98,6 +100,11 @@ public String getConnectionString() {
98100
@Nullable
99101
public Boolean treatPrecisionlessNumAsDeci;
100102

103+
@Name(OracleConstants.TREAT_AS_TIMESTAMP_FOR_LOCAL_TIME_ZONE)
104+
@Description("A hidden field to handle mapping of Oracle Timestamp_LTZ data type to BQ Timestamp.")
105+
@Nullable
106+
public Boolean treatAsTimestampForLocalTimeZone;
107+
101108
@Override
102109
protected int getDefaultPort() {
103110
return 1521;
@@ -128,6 +135,10 @@ public Boolean getTreatPrecisionlessNumAsDeci() {
128135
return Boolean.TRUE.equals(treatPrecisionlessNumAsDeci);
129136
}
130137

138+
public Boolean getTreatAsTimestampForLocalTimeZone() {
139+
return Boolean.TRUE.equals(treatAsTimestampForLocalTimeZone);
140+
}
141+
131142
@Override
132143
public Properties getConnectionArgumentsProperties() {
133144
Properties prop = super.getConnectionArgumentsProperties();

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private OracleConstants() {
4646
public static final String USE_SSL = "useSSL";
4747
public static final String TREAT_AS_OLD_TIMESTAMP = "treatAsOldTimestamp";
4848
public static final String TREAT_PRECISIONLESSNUM_AS_DECI = "treatPrecisionlessNumAsDeci";
49+
public static final String TREAT_AS_TIMESTAMP_FOR_LOCAL_TIME_ZONE
50+
= "treatAsTimestampForLocalTimeZone";
4951

5052
/**
5153
* Constructs the Oracle connection string based on the provided connection type, host, port, and database.

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleSource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ protected SchemaReader getSchemaReader() {
6868
// handle schema to make it backward compatible.
6969
boolean treatAsOldTimestamp = oracleSourceConfig.getConnection().getTreatAsOldTimestamp();
7070
boolean treatPrecisionlessNumAsDeci = oracleSourceConfig.getConnection().getTreatPrecisionlessNumAsDeci();
71+
boolean treatAsTimestampForLocalTimeZone = oracleSourceConfig.getConnection().getTreatAsTimestampForLocalTimeZone();
7172

72-
return new OracleSourceSchemaReader(null, treatAsOldTimestamp, treatPrecisionlessNumAsDeci);
73+
return new OracleSourceSchemaReader(null, treatAsOldTimestamp, treatPrecisionlessNumAsDeci, treatAsTimestampForLocalTimeZone);
7374
}
7475

7576
@Override
@@ -137,10 +138,10 @@ public OracleSourceConfig(String host, int port, String user, String password, S
137138
int defaultBatchValue, int defaultRowPrefetch,
138139
String importQuery, Integer numSplits, int fetchSize,
139140
String boundingQuery, String splitBy, Boolean useSSL, Boolean treatAsOldTimestamp,
140-
Boolean treatPrecisionlessNumAsDeci) {
141+
Boolean treatPrecisionlessNumAsDeci, Boolean treatAsTimestampForLocalTimeZone) {
141142
this.connection = new OracleConnectorConfig(host, port, user, password, jdbcPluginName, connectionArguments,
142143
connectionType, database, role, useSSL, treatAsOldTimestamp,
143-
treatPrecisionlessNumAsDeci);
144+
treatPrecisionlessNumAsDeci, treatAsTimestampForLocalTimeZone);
144145
this.defaultBatchValue = defaultBatchValue;
145146
this.defaultRowPrefetch = defaultRowPrefetch;
146147
this.fetchSize = fetchSize;

oracle-plugin/src/main/java/io/cdap/plugin/oracle/OracleSourceSchemaReader.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.collect.ImmutableSet;
2020
import io.cdap.cdap.api.data.schema.Schema;
2121
import io.cdap.plugin.db.CommonSchemaReader;
22+
import org.jetbrains.annotations.NotNull;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425

@@ -68,15 +69,17 @@ public class OracleSourceSchemaReader extends CommonSchemaReader {
6869
private final String sessionID;
6970
private final Boolean isTimestampOldBehavior;
7071
private final Boolean isPrecisionlessNumAsDecimal;
72+
private final Boolean isLtzFieldTimestamp;
7173

7274
public OracleSourceSchemaReader() {
73-
this(null, false, false);
75+
this(null, false, false, false);
7476
}
7577
public OracleSourceSchemaReader(@Nullable String sessionID, boolean isTimestampOldBehavior,
76-
boolean isPrecisionlessNumAsDecimal) {
78+
boolean isPrecisionlessNumAsDecimal, boolean isLtzFieldTimestamp) {
7779
this.sessionID = sessionID;
7880
this.isTimestampOldBehavior = isTimestampOldBehavior;
7981
this.isPrecisionlessNumAsDecimal = isPrecisionlessNumAsDecimal;
82+
this.isLtzFieldTimestamp = isLtzFieldTimestamp;
8083
}
8184

8285
@Override
@@ -87,8 +90,7 @@ public Schema getSchema(ResultSetMetaData metadata, int index) throws SQLExcepti
8790
case TIMESTAMP_TZ:
8891
return isTimestampOldBehavior ? Schema.of(Schema.Type.STRING) : Schema.of(Schema.LogicalType.TIMESTAMP_MICROS);
8992
case TIMESTAMP_LTZ:
90-
return isTimestampOldBehavior ? Schema.of(Schema.LogicalType.TIMESTAMP_MICROS)
91-
: Schema.of(Schema.LogicalType.DATETIME);
93+
return getTimestampLtzSchema();
9294
case Types.TIMESTAMP:
9395
return isTimestampOldBehavior ? super.getSchema(metadata, index) : Schema.of(Schema.LogicalType.DATETIME);
9496
case BINARY_FLOAT:
@@ -139,6 +141,14 @@ public Schema getSchema(ResultSetMetaData metadata, int index) throws SQLExcepti
139141
}
140142
}
141143

144+
private @NotNull Schema getTimestampLtzSchema() {
145+
if (Boolean.TRUE.equals(isLtzFieldTimestamp)) {
146+
return Schema.of(Schema.LogicalType.TIMESTAMP_MICROS);
147+
}
148+
return isTimestampOldBehavior ? Schema.of(Schema.LogicalType.TIMESTAMP_MICROS)
149+
: Schema.of(Schema.LogicalType.DATETIME);
150+
}
151+
142152
@Override
143153
public boolean shouldIgnoreColumn(ResultSetMetaData metadata, int index) throws SQLException {
144154
if (sessionID == null) {

oracle-plugin/widgets/Oracle-batchsource.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,25 @@
158158
]
159159
}
160160
},
161+
{
162+
"widget-type": "hidden",
163+
"label": "Treat as Timestamp for Timestamp_LTZ",
164+
"name": "treatAsTimestampForLocalTimeZone",
165+
"widget-attributes": {
166+
"layout": "inline",
167+
"default": "false",
168+
"options": [
169+
{
170+
"id": "true",
171+
"label": "true"
172+
},
173+
{
174+
"id": "false",
175+
"label": "false"
176+
}
177+
]
178+
}
179+
},
161180
{
162181
"name": "connectionType",
163182
"label": "Connection Type",

oracle-plugin/widgets/Oracle-connector.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@
167167
}
168168
]
169169
}
170+
},
171+
{
172+
"widget-type": "hidden",
173+
"label": "Treat as Timestamp for Timestamp_LTZ",
174+
"name": "treatAsTimestampForLocalTimeZone",
175+
"widget-attributes": {
176+
"layout": "inline",
177+
"default": "false",
178+
"options": [
179+
{
180+
"id": "true",
181+
"label": "true"
182+
},
183+
{
184+
"id": "false",
185+
"label": "false"
186+
}
187+
]
188+
}
170189
}
171190
]
172191
},

0 commit comments

Comments
 (0)