Skip to content

Commit f319f75

Browse files
committed
Fix index issue & add readme details
1 parent b10d1bb commit f319f75

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ spark.destination.autocorrect.missing true|false
6262
spark.destination.autocorrect.mismatch true|false
6363
```
6464

65+
# Migrating specific partition ranges
66+
- You can also use the tool to migrate specific partition ranges, use class option `--class datastax.astra.migrate.MigratePartitionsFromFile` as shown below
67+
```
68+
./spark-submit --properties-file sparkConf.properties /
69+
--master "local[*]" /
70+
--class datastax.astra.migrate.MigratePartitionsFromFile cassandra-data-migrator-1.x.jar &> logfile_name.txt
71+
```
72+
73+
When running in above mode the tool assumes a `partitions.csv` file to be present in the current folder in the below format, where each line (`min,max`) represents a partition-range
74+
```
75+
-507900353496146534,-107285462027022883
76+
-506781526266485690,1506166634797362039
77+
2637884402540451982,4638499294009575633
78+
798869613692279889,8699484505161403540
79+
```
80+
This mode is specifically useful to processes a subset of partition-ranges that may have generated errors as a result of a previous long-running job to migrate a large table.
81+
6582
# Additional features
6683
- [Counter tables](https://docs.datastax.com/en/dse/6.8/cql/cql/cql_using/useCountersConcept.html)
6784
- Preserve [writetimes](https://docs.datastax.com/en/dse/6.8/cql/cql/cql_reference/cql_commands/cqlSelect.html#cqlSelect__retrieving-the-datetime-a-write-occurred-p) and [TTL](https://docs.datastax.com/en/dse/6.8/cql/cql/cql_reference/cql_commands/cqlSelect.html#cqlSelect__ref-select-ttl-p)

src/main/java/datastax/astra/migrate/AbstractJobSession.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.List;
1414
import java.util.Map;
1515
import java.util.Set;
16+
import java.util.stream.IntStream;
1617

1718
public class AbstractJobSession extends BaseJobSession {
1819

@@ -156,19 +157,13 @@ public List<MigrateDataType> getTypes(String types) {
156157
}
157158

158159
public int getLargestTTL(Row sourceRow) {
159-
int ttl = 0;
160-
for (Integer ttlCol : ttlCols) {
161-
ttl = Math.max(ttl, sourceRow.getInt(selectColTypes.size() + ttlCol - 1));
162-
}
163-
return ttl;
160+
return IntStream.range(0, ttlCols.size())
161+
.map(i -> sourceRow.getInt(selectColTypes.size() + i)).max().getAsInt();
164162
}
165163

166164
public long getLargestWriteTimeStamp(Row sourceRow) {
167-
long writeTimestamp = 0;
168-
for (Integer writeTimeStampCol : writeTimeStampCols) {
169-
writeTimestamp = Math.max(writeTimestamp, sourceRow.getLong(selectColTypes.size() + ttlCols.size() + writeTimeStampCol - 1));
170-
}
171-
return writeTimestamp;
165+
return IntStream.range(0, writeTimeStampCols.size())
166+
.mapToLong(i -> sourceRow.getLong(selectColTypes.size() + ttlCols.size() + i)).max().getAsLong();
172167
}
173168

174169
public BoundStatement selectFromAstra(PreparedStatement selectStatement, Row sourceRow) {

src/main/scala/datastax/astra/migrate/BaseJob.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.apache.spark.sql.SparkSession
44
import org.slf4j.LoggerFactory
55

66
import java.math.BigInteger
7-
import java.lang.Long
87

98
class BaseJob extends App {
109

src/main/scala/datastax/astra/migrate/MigratePartitionsFromFile.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package datastax.astra.migrate
33
import com.datastax.spark.connector.cql.CassandraConnector
44
import org.slf4j.LoggerFactory
55

6-
import java.math.BigInteger
76
import scala.collection.JavaConversions._
8-
import java.lang.Long
97

108
object MigratePartitionsFromFile extends AbstractJob {
119

0 commit comments

Comments
 (0)