Skip to content

Commit d019ad3

Browse files
authored
Implemented skip column feature (#348)
* Implemented skip column feature * Var naming update
1 parent b49b00c commit d019ad3

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/main/java/com/datastax/cdm/properties/KnownProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public enum PropertyType {
8080
public static final String ORIGIN_WRITETIME_NAMES = "spark.cdm.schema.origin.column.writetime.names";
8181
public static final String ALLOW_COLL_FOR_WRITETIME_TTL_CALC = "spark.cdm.schema.ttlwritetime.calc.useCollections";
8282

83+
public static final String ORIGIN_COLUMN_NAMES_TO_SKIP = "spark.cdm.schema.origin.column.skip";
8384
public static final String ORIGIN_COLUMN_NAMES_TO_TARGET = "spark.cdm.schema.origin.column.names.to.target";
8485

8586
static {
@@ -93,6 +94,7 @@ public enum PropertyType {
9394
defaults.put(ORIGIN_WRITETIME_AUTO, "true");
9495
types.put(ALLOW_COLL_FOR_WRITETIME_TTL_CALC, PropertyType.BOOLEAN);
9596
defaults.put(ALLOW_COLL_FOR_WRITETIME_TTL_CALC, "false");
97+
types.put(ORIGIN_COLUMN_NAMES_TO_SKIP, PropertyType.STRING_LIST);
9698
types.put(ORIGIN_COLUMN_NAMES_TO_TARGET, PropertyType.STRING_LIST);
9799
}
98100

src/main/java/com/datastax/cdm/schema/CqlTable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727
import java.util.stream.IntStream;
2828

29+
import org.apache.commons.collections4.CollectionUtils;
2930
import org.apache.commons.lang3.StringUtils;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
@@ -470,7 +471,9 @@ private void setCqlMetadata(CqlSession cqlSession) {
470471
}
471472
}
472473
String columnName = extractColumnName;
474+
List<String> skipColumns = propertyHelper.getStringList(KnownProperties.ORIGIN_COLUMN_NAMES_TO_SKIP);
473475
this.cqlAllColumns = tableMetadata.getColumns().values().stream().filter(md -> !this.cqlAllColumns.contains(md))
476+
.filter(md -> CollectionUtils.isEmpty(skipColumns) || !skipColumns.contains(md.getName().asCql(true)))
474477
.filter(md -> !extractJsonExclusive || md.getName().asCql(true).endsWith(columnName))
475478
.collect(Collectors.toCollection(() -> this.cqlAllColumns));
476479

src/resources/cdm-detailed.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ spark.cdm.connect.target.password cassandra
9696
# Other Parameters:
9797
# spark.cdm.schema
9898
# .origin.column
99+
# .skip : Default is empty. A comma-separated list of columns that should be skipped.
100+
# Only use this property when both origin and target tables contain the above columns.
101+
# If the target table does not contain the column, CDM will detect it and auto-skip.
102+
#
99103
# .names.to.target : Default is empty. If column names are changed between Origin and Target, then
100104
# this map-like list provides a mechanism to associate the two. The format is
101105
# origin_column_name:target_column_name. The list is comma-separated. Only renamed

src/test/java/com/datastax/cdm/schema/CqlTableTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.datastax.cdm.schema;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
1920

2021
import org.junit.jupiter.api.Test;
2122

@@ -39,4 +40,12 @@ void testCL() {
3940
assertEquals(CqlTable.mapToConsistencyLevel("all"), ConsistencyLevel.ALL);
4041
}
4142

43+
@Test
44+
void testformatName() {
45+
assertNull(CqlTable.formatName(null));
46+
assertEquals("", CqlTable.formatName(""));
47+
assertEquals("\"KS123ks.T123able\"", CqlTable.formatName("KS123ks.T123able"));
48+
assertEquals("\"Ks.Table\"", CqlTable.formatName("\"Ks.Table\""));
49+
assertEquals("\"ks.table\"", CqlTable.formatName("ks.table"));
50+
}
4251
}

0 commit comments

Comments
 (0)