@@ -35,20 +35,17 @@ protected AbstractJobSession(CqlSession sourceSession, CqlSession astraSession,
35
35
sourceKeyspaceTable = sparkConf .get ("spark.source.keyspaceTable" );
36
36
astraKeyspaceTable = sparkConf .get ("spark.destination.keyspaceTable" );
37
37
38
- isPreserveTTLWritetime = Boolean .parseBoolean (sparkConf .get ("spark.preserveTTLWriteTime" , "false" ));
39
- if (isPreserveTTLWritetime ) {
40
- String ttlColsStr = sparkConf .get ("spark.preserveTTLWriteTime.ttl.cols" );
41
- if (null != ttlColsStr && ttlColsStr .trim ().length () > 0 ) {
42
- for (String ttlCol : ttlColsStr .split ("," )) {
43
- ttlCols .add (Integer .parseInt (ttlCol ));
44
- }
38
+ String ttlColsStr = sparkConf .get ("spark.query.ttl.cols" );
39
+ if (null != ttlColsStr && ttlColsStr .trim ().length () > 0 ) {
40
+ for (String ttlCol : ttlColsStr .split ("," )) {
41
+ ttlCols .add (Integer .parseInt (ttlCol ));
45
42
}
43
+ }
46
44
47
- String writeTimestampColsStr = sparkConf .get ("spark.preserveTTLWriteTime.writetime.cols" );
48
- if (null != writeTimestampColsStr && writeTimestampColsStr .trim ().length () > 0 ) {
49
- for (String writeTimeStampCol : writeTimestampColsStr .split ("," )) {
50
- writeTimeStampCols .add (Integer .parseInt (writeTimeStampCol ));
51
- }
45
+ String writeTimestampColsStr = sparkConf .get ("spark.query.writetime.cols" );
46
+ if (null != writeTimestampColsStr && writeTimestampColsStr .trim ().length () > 0 ) {
47
+ for (String writeTimeStampCol : writeTimestampColsStr .split ("," )) {
48
+ writeTimeStampCols .add (Integer .parseInt (writeTimeStampCol ));
52
49
}
53
50
}
54
51
@@ -75,26 +72,22 @@ protected AbstractJobSession(CqlSession sourceSession, CqlSession astraSession,
75
72
logger .info ("PARAM -- Destination Keyspace Table: " + astraKeyspaceTable );
76
73
logger .info ("PARAM -- ReadRateLimit: " + readLimiter .getRate ());
77
74
logger .info ("PARAM -- WriteRateLimit: " + writeLimiter .getRate ());
78
- logger .info ("PARAM -- WriteTimestampFilter: " + writeTimeStampFilter );
79
- logger .info ("PARAM -- WriteTimestampFilterCols: " + writeTimeStampCols );
80
- logger .info ("PARAM -- isPreserveTTLWritetime: " + isPreserveTTLWritetime );
81
- logger .info ("PARAM -- isPreserveTTLWritetime: " + isPreserveTTLWritetime );
82
75
logger .info ("PARAM -- TTLCols: " + ttlCols );
76
+ logger .info ("PARAM -- WriteTimestampFilterCols: " + writeTimeStampCols );
77
+ logger .info ("PARAM -- WriteTimestampFilter: " + writeTimeStampFilter );
83
78
84
79
String selectCols = sparkConf .get ("spark.query.source" );
85
80
String partionKey = sparkConf .get ("spark.query.source.partitionKey" );
86
81
String sourceSelectCondition = sparkConf .get ("spark.query.condition" , "" );
87
82
88
83
final StringBuilder selectTTLWriteTimeCols = new StringBuilder ();
89
- if (isPreserveTTLWritetime ) {
90
- String [] allCols = selectCols .split ("," );
91
- ttlCols .forEach (col -> {
92
- selectTTLWriteTimeCols .append (",ttl(" + allCols [col ] + ")" );
93
- });
94
- writeTimeStampCols .forEach (col -> {
95
- selectTTLWriteTimeCols .append (",writetime(" + allCols [col ] + ")" );
96
- });
97
- }
84
+ String [] allCols = selectCols .split ("," );
85
+ ttlCols .forEach (col -> {
86
+ selectTTLWriteTimeCols .append (",ttl(" + allCols [col ] + ")" );
87
+ });
88
+ writeTimeStampCols .forEach (col -> {
89
+ selectTTLWriteTimeCols .append (",writetime(" + allCols [col ] + ")" );
90
+ });
98
91
String fullSelectQuery = "select " + selectCols + selectTTLWriteTimeCols .toString () + " from " + sourceKeyspaceTable + " where token(" + partionKey .trim ()
99
92
+ ") >= ? and token(" + partionKey .trim () + ") <= ? " + sourceSelectCondition + " ALLOW FILTERING" ;
100
93
sourceSelectStatement = sourceSession .prepare (fullSelectQuery );
@@ -103,7 +96,7 @@ protected AbstractJobSession(CqlSession sourceSession, CqlSession astraSession,
103
96
selectColTypes = getTypes (sparkConf .get ("spark.query.types" ));
104
97
String idCols = sparkConf .get ("spark.query.destination.id" , "" );
105
98
idColTypes = selectColTypes .subList (0 , idCols .split ("," ).length );
106
-
99
+
107
100
String insertCols = sparkConf .get ("spark.query.destination" , "" );
108
101
if (null == insertCols || insertCols .trim ().isEmpty ()) {
109
102
insertCols = selectCols ;
@@ -140,11 +133,16 @@ protected AbstractJobSession(CqlSession sourceSession, CqlSession astraSession,
140
133
}
141
134
}
142
135
143
- if (isPreserveTTLWritetime ) {
144
- astraInsertStatement = astraSession .prepare ("insert into " + astraKeyspaceTable + " (" + insertCols + ") VALUES (" + insertBinds + ") using TTL ? and TIMESTAMP ?" );
145
- } else {
146
- astraInsertStatement = astraSession .prepare ("insert into " + astraKeyspaceTable + " (" + insertCols + ") VALUES (" + insertBinds + ")" );
136
+ String fullInsertQuery = "insert into " + astraKeyspaceTable + " (" + insertCols + ") VALUES (" + insertBinds + ")" ;
137
+ if (!ttlCols .isEmpty ()) {
138
+ fullInsertQuery += " USING TTL ?" ;
139
+ if (!writeTimeStampCols .isEmpty ()) {
140
+ fullInsertQuery += " AND TIMESTAMP ?" ;
141
+ }
142
+ } else if (!writeTimeStampCols .isEmpty ()) {
143
+ fullInsertQuery += " USING TIMESTAMP ?" ;
147
144
}
145
+ astraInsertStatement = astraSession .prepare (fullInsertQuery );
148
146
}
149
147
}
150
148
0 commit comments