Skip to content

Commit 068942e

Browse files
Enable xml type support for oracle for dts-connectors only
1 parent 085e485 commit 068942e

8 files changed

Lines changed: 90 additions & 10 deletions

File tree

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
@@ -115,7 +115,8 @@ protected DBConnectorPath getDBConnectorPath(String path) {
115115
protected SchemaReader getSchemaReader(String sessionID) {
116116
return new OracleSourceSchemaReader(sessionID, config.getTreatAsOldTimestamp(),
117117
config.getTreatPrecisionlessNumAsDeci(),
118-
config.getTreatTimestampLTZAsTimestamp());
118+
config.getTreatTimestampLTZAsTimestamp(),
119+
config.getXmlTypeEnabled());
119120
}
120121

121122
@Override

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ 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, null);
45+
null, 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,
5151
@Nullable Boolean treatPrecisionlessNumAsDeci,
52-
@Nullable Boolean treatTimestampLTZAsTimestamp) {
52+
@Nullable Boolean treatTimestampLTZAsTimestamp,
53+
@Nullable Boolean enableXmlType) {
5354

5455
this.host = host;
5556
this.port = port;
@@ -64,6 +65,7 @@ public OracleConnectorConfig(String host, int port, String user, String password
6465
this.treatAsOldTimestamp = treatAsOldTimestamp;
6566
this.treatPrecisionlessNumAsDeci = treatPrecisionlessNumAsDeci;
6667
this.treatTimestampLTZAsTimestamp = treatTimestampLTZAsTimestamp;
68+
this.enableXmlType = enableXmlType;
6769
}
6870

6971
@Override
@@ -105,6 +107,12 @@ public String getConnectionString() {
105107
@Nullable
106108
public Boolean treatTimestampLTZAsTimestamp;
107109

110+
@Name(OracleConstants.ENABLE_XML_TYPE)
111+
@Description("A hidden field to handle mapping of Oracle XML type to BQ String.")
112+
@Nullable
113+
public Boolean enableXmlType;
114+
115+
108116
@Override
109117
protected int getDefaultPort() {
110118
return 1521;
@@ -139,6 +147,10 @@ public Boolean getTreatTimestampLTZAsTimestamp() {
139147
return Boolean.TRUE.equals(treatTimestampLTZAsTimestamp);
140148
}
141149

150+
public Boolean getXmlTypeEnabled() {
151+
return Boolean.TRUE.equals(enableXmlType);
152+
}
153+
142154
@Override
143155
public Properties getConnectionArgumentsProperties() {
144156
Properties prop = super.getConnectionArgumentsProperties();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private OracleConstants() {
4747
public static final String TREAT_AS_OLD_TIMESTAMP = "treatAsOldTimestamp";
4848
public static final String TREAT_PRECISIONLESSNUM_AS_DECI = "treatPrecisionlessNumAsDeci";
4949
public static final String TREAT_TIMESTAMP_LTZ_AS_TIMESTAMP = "treatTimestampLTZAsTimestamp";
50+
public static final String ENABLE_XML_TYPE = "enableXmlType";
5051

5152
/**
5253
* 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ protected SchemaReader getSchemaReader() {
6969
boolean treatAsOldTimestamp = oracleSourceConfig.getConnection().getTreatAsOldTimestamp();
7070
boolean treatPrecisionlessNumAsDeci = oracleSourceConfig.getConnection().getTreatPrecisionlessNumAsDeci();
7171
boolean treatTimestampLTZAsTimestamp = oracleSourceConfig.getConnection().getTreatTimestampLTZAsTimestamp();
72+
boolean enableXmlType = oracleSourceConfig.getConnection().getXmlTypeEnabled();
7273

7374
return new OracleSourceSchemaReader(null, treatAsOldTimestamp, treatPrecisionlessNumAsDeci,
74-
treatTimestampLTZAsTimestamp);
75+
treatTimestampLTZAsTimestamp, enableXmlType);
7576
}
7677

7778
@Override
@@ -139,10 +140,12 @@ public OracleSourceConfig(String host, int port, String user, String password, S
139140
int defaultBatchValue, int defaultRowPrefetch,
140141
String importQuery, Integer numSplits, int fetchSize,
141142
String boundingQuery, String splitBy, Boolean useSSL, Boolean treatAsOldTimestamp,
142-
Boolean treatPrecisionlessNumAsDeci, Boolean treatTimestampLTZAsTimestamp) {
143+
Boolean treatPrecisionlessNumAsDeci, Boolean treatTimestampLTZAsTimestamp,
144+
Boolean enableXmlType) {
143145
this.connection = new OracleConnectorConfig(host, port, user, password, jdbcPluginName, connectionArguments,
144146
connectionType, database, role, useSSL, treatAsOldTimestamp,
145-
treatPrecisionlessNumAsDeci, treatTimestampLTZAsTimestamp);
147+
treatPrecisionlessNumAsDeci, treatTimestampLTZAsTimestamp,
148+
enableXmlType);
146149
this.defaultBatchValue = defaultBatchValue;
147150
this.defaultRowPrefetch = defaultRowPrefetch;
148151
this.fetchSize = fetchSize;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class OracleSourceSchemaReader extends CommonSchemaReader {
6161
BINARY_DOUBLE,
6262
BFILE,
6363
LONG,
64+
Types.SQLXML,
6465
LONG_RAW,
6566
Types.NUMERIC,
6667
Types.DECIMAL
@@ -70,16 +71,19 @@ public class OracleSourceSchemaReader extends CommonSchemaReader {
7071
private final Boolean isTimestampOldBehavior;
7172
private final Boolean isPrecisionlessNumAsDecimal;
7273
private final Boolean isTimestampLtzFieldTimestamp;
74+
private final Boolean isXmlTypeEnabled;
7375

7476
public OracleSourceSchemaReader() {
75-
this(null, false, false, false);
77+
this(null, false, false, false, false);
7678
}
7779
public OracleSourceSchemaReader(@Nullable String sessionID, boolean isTimestampOldBehavior,
78-
boolean isPrecisionlessNumAsDecimal, boolean isTimestampLtzFieldTimestamp) {
80+
boolean isPrecisionlessNumAsDecimal, boolean isTimestampLtzFieldTimestamp,
81+
boolean isXmlTypeEnabled) {
7982
this.sessionID = sessionID;
8083
this.isTimestampOldBehavior = isTimestampOldBehavior;
8184
this.isPrecisionlessNumAsDecimal = isPrecisionlessNumAsDecimal;
8285
this.isTimestampLtzFieldTimestamp = isTimestampLtzFieldTimestamp;
86+
this.isXmlTypeEnabled = isXmlTypeEnabled;
8387
}
8488

8589
@Override
@@ -104,6 +108,8 @@ public Schema getSchema(ResultSetMetaData metadata, int index) throws SQLExcepti
104108
case INTERVAL_YM:
105109
case LONG:
106110
return Schema.of(Schema.Type.STRING);
111+
case Types.SQLXML:
112+
return isXmlTypeEnabled ? Schema.of(Schema.Type.STRING) : super.getSchema(metadata, index);
107113
case Types.NUMERIC:
108114
case Types.DECIMAL:
109115
// FLOAT and REAL are returned as java.sql.Types.NUMERIC but with value that is a java.lang.Double

oracle-plugin/src/test/java/io/cdap/plugin/oracle/OracleSchemaReaderTest.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
import java.sql.ResultSet;
2828
import java.sql.ResultSetMetaData;
2929
import java.sql.SQLException;
30+
import java.sql.Types;
3031
import java.util.List;
3132

3233
public class OracleSchemaReaderTest {
3334

3435
@Test
3536
public void getSchema_timestampLTZFieldTrue_returnTimestamp() throws SQLException {
36-
OracleSourceSchemaReader schemaReader = new OracleSourceSchemaReader(null, false, false, true);
37+
OracleSourceSchemaReader schemaReader = new OracleSourceSchemaReader(null, false, false, true, false);
3738

3839
ResultSet resultSet = Mockito.mock(ResultSet.class);
3940
ResultSetMetaData metadata = Mockito.mock(ResultSetMetaData.class);
@@ -64,7 +65,7 @@ public void getSchema_timestampLTZFieldTrue_returnTimestamp() throws SQLExceptio
6465

6566
@Test
6667
public void getSchema_timestampLTZFieldFalse_returnDatetime() throws SQLException {
67-
OracleSourceSchemaReader schemaReader = new OracleSourceSchemaReader(null, false, false, false);
68+
OracleSourceSchemaReader schemaReader = new OracleSourceSchemaReader(null, false, false, false, false);
6869

6970
ResultSet resultSet = Mockito.mock(ResultSet.class);
7071
ResultSetMetaData metadata = Mockito.mock(ResultSetMetaData.class);
@@ -91,4 +92,22 @@ public void getSchema_timestampLTZFieldFalse_returnDatetime() throws SQLExceptio
9192
Assert.assertEquals(expectedSchemaFields.get(1).getName(), actualSchemaFields.get(1).getName());
9293
Assert.assertEquals(expectedSchemaFields.get(1).getSchema(), actualSchemaFields.get(1).getSchema());
9394
}
95+
96+
@Test
97+
public void getSchema_xmlField_returnString() throws SQLException {
98+
OracleSourceSchemaReader schemaReader = new OracleSourceSchemaReader(null, false, false, false, true);
99+
ResultSet resultSet = Mockito.mock(ResultSet.class);
100+
ResultSetMetaData metadata = Mockito.mock(ResultSetMetaData.class);
101+
Mockito.when(resultSet.getMetaData()).thenReturn(metadata);
102+
Mockito.when(metadata.getColumnCount()).thenReturn(1);
103+
Mockito.when(metadata.getColumnType(1)).thenReturn(Types.SQLXML);
104+
Mockito.when(metadata.getColumnName(1)).thenReturn("xmlData");
105+
106+
List<Schema.Field> actualSchemaFields = schemaReader.getSchemaFields(resultSet);
107+
108+
List<Schema.Field> expectedSchemaFields = Lists.newArrayList();
109+
expectedSchemaFields.add(Schema.Field.of("xmlData", Schema.of(Schema.Type.STRING)));
110+
Assert.assertEquals(expectedSchemaFields.get(0).getName(), actualSchemaFields.get(0).getName());
111+
Assert.assertEquals(expectedSchemaFields.get(0).getSchema(), actualSchemaFields.get(0).getSchema());
112+
}
94113
}

oracle-plugin/widgets/Oracle-batchsource.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@
177177
]
178178
}
179179
},
180+
{
181+
"widget-type": "hidden",
182+
"label": "Enable Xml Type",
183+
"name": "enableXmlType",
184+
"widget-attributes": {
185+
"layout": "inline",
186+
"default": "false",
187+
"options": [
188+
{
189+
"id": "true",
190+
"label": "true"
191+
},
192+
{
193+
"id": "false",
194+
"label": "false"
195+
}
196+
]
197+
}
198+
},
180199
{
181200
"name": "connectionType",
182201
"label": "Connection Type",

oracle-plugin/widgets/Oracle-connector.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@
186186
}
187187
]
188188
}
189+
},
190+
{
191+
"widget-type": "hidden",
192+
"label": "Enable Xml Type",
193+
"name": "enableXmlType",
194+
"widget-attributes": {
195+
"layout": "inline",
196+
"default": "false",
197+
"options": [
198+
{
199+
"id": "true",
200+
"label": "true"
201+
},
202+
{
203+
"id": "false",
204+
"label": "false"
205+
}
206+
]
207+
}
189208
}
190209
]
191210
},

0 commit comments

Comments
 (0)