Skip to content

Commit 209b232

Browse files
authored
Bug/cdm 65 (#158)
* CDM-65 formatting names within writetime and ttl * CDM-66 writetime function no longer called when custom writetime is provided --------- Co-authored-by: Phil Miesle <[email protected]>
1 parent 7ce675e commit 209b232

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/main/java/com/datastax/cdm/feature/WritetimeTTL.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void validateTTLColumns(CqlTable originTable) {
213213
}
214214
}
215215

216-
newColumnNames.add("TTL(" + ttlName + ")");
216+
newColumnNames.add("TTL(" + CqlTable.formatName(ttlName) + ")");
217217
newColumnDataTypes.add(DataTypes.INT);
218218
}
219219

@@ -225,7 +225,7 @@ private void validateTTLColumns(CqlTable originTable) {
225225
}
226226

227227
private void validateWritetimeColumns(CqlTable originTable) {
228-
if (writetimeNames == null || writetimeNames.isEmpty()) {
228+
if (writetimeNames == null || writetimeNames.isEmpty() || customWritetime > 0) {
229229
return;
230230
}
231231

@@ -245,7 +245,7 @@ private void validateWritetimeColumns(CqlTable originTable) {
245245
}
246246
}
247247

248-
newColumnNames.add("WRITETIME(" + writetimeName + ")");
248+
newColumnNames.add("WRITETIME(" + CqlTable.formatName(writetimeName) + ")");
249249
newColumnDataTypes.add(DataTypes.BIGINT);
250250
}
251251

src/test/java/com/datastax/cdm/feature/TTLAndWritetimeTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import static org.junit.jupiter.api.Assertions.*;
1414
import static org.mockito.ArgumentMatchers.anyString;
1515
import static org.mockito.ArgumentMatchers.eq;
16-
import static org.mockito.Mockito.mock;
17-
import static org.mockito.Mockito.when;
16+
import static org.mockito.Mockito.*;
1817

1918
public class TTLAndWritetimeTest extends CommonMocks {
2019

@@ -385,6 +384,7 @@ public void validateEmptyTTLColumn() {
385384

386385
@Test
387386
public void validateInvalidCustomWritetimeColumn() {
387+
when(propertyHelper.getLong(KnownProperties.TRANSFORM_CUSTOM_WRITETIME)).thenReturn(0L);
388388
when(propertyHelper.getStringList(KnownProperties.ORIGIN_WRITETIME_NAMES)).thenReturn(Collections.singletonList("invalid"));
389389
when(originTable.indexOf("invalid")).thenReturn(-1);
390390
assertAll(
@@ -462,4 +462,24 @@ public void testZeroIncrementWithUnfrozenList() {
462462
assertTrue(feature.isEnabled());
463463
}
464464

465+
@Test
466+
public void customWriteTime_withAutoWritetime() {
467+
when(propertyHelper.getLong(KnownProperties.TRANSFORM_CUSTOM_WRITETIME)).thenReturn(12345L);
468+
when(propertyHelper.getStringList(KnownProperties.ORIGIN_WRITETIME_NAMES)).thenReturn(null);
469+
when(propertyHelper.getBoolean(KnownProperties.ORIGIN_WRITETIME_AUTO)).thenReturn(true);
470+
when(propertyHelper.getLong(KnownProperties.FILTER_WRITETS_MIN)).thenReturn(null);
471+
when(propertyHelper.getLong(KnownProperties.FILTER_WRITETS_MAX)).thenReturn(null);
472+
when(propertyHelper.getStringList(KnownProperties.ORIGIN_TTL_NAMES)).thenReturn(null);
473+
when(propertyHelper.getBoolean(KnownProperties.ORIGIN_TTL_AUTO)).thenReturn(false);
474+
475+
feature.loadProperties(propertyHelper);
476+
feature.initializeAndValidate(originTable, targetTable);
477+
478+
assertAll(
479+
() -> assertFalse(feature.hasWriteTimestampFilter(), "hasWriteTimestampFilter"),
480+
() -> assertTrue(feature.hasWritetimeColumns(), "hasWritetimeColumns")
481+
);
482+
483+
verify(originTable, times(0)).extendColumns(any(),any());
484+
}
465485
}

0 commit comments

Comments
 (0)