Skip to content

Commit

Permalink
Code formatting and import organization only change. Includes no func…
Browse files Browse the repository at this point in the history
…tional changes.
  • Loading branch information
pravinbhat committed Sep 3, 2024
1 parent 4073b87 commit f079698
Show file tree
Hide file tree
Showing 106 changed files with 4,249 additions and 3,794 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release Notes
## [4.3.7] - 2024-09-03
- Added property `spark.cdm.transform.custom.ttl` to allow a custom constant value to be set for TTL instead of using the values from `origin` rows.
- Repo wide code formating & imports organization

## [4.3.6] - 2024-08-29
- Added `overwrite` option to conditionally check or skip `Validation` when it has a non-null value in `target` for the `spark.cdm.feature.extractJson` feature.
Expand Down
39 changes: 37 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>datastax.cdm</groupId>
Expand Down Expand Up @@ -288,7 +290,7 @@
<limit>
<counter>LINE</counter>
<value>MISSEDCOUNT</value>
<maximum>1400</maximum>
<maximum>1500</maximum>
</limit>
</limits>
</rule>
Expand All @@ -313,6 +315,39 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>1.9.0</version>
<configuration>
<groups>java.,javax.,org.,com.</groups>
<staticGroups>java,*</staticGroups>
</configuration>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.23.0</version>
<configuration>
<compilerSource>11</compilerSource>
<compilerCompliance>11</compilerCompliance>
<compilerTargetPlatform>11</compilerTargetPlatform>
</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
45 changes: 27 additions & 18 deletions src/main/java/com/datastax/cdm/cql/EnhancedSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
*/
package com.datastax.cdm.cql;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.datastax.cdm.cql.codec.CodecFactory;
import com.datastax.cdm.cql.codec.Codecset;
import com.datastax.cdm.cql.statement.*;
import com.datastax.cdm.data.PKFactory;
import com.datastax.cdm.properties.KnownProperties;
import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.cdm.schema.CqlTable;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException;
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
import com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import com.datastax.cdm.cql.codec.CodecFactory;
import com.datastax.cdm.cql.codec.Codecset;
import com.datastax.cdm.data.PKFactory;
import com.datastax.cdm.properties.KnownProperties;
import com.datastax.cdm.properties.PropertyHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class EnhancedSession {
public Logger logger = LoggerFactory.getLogger(this.getClass().getName());
Expand All @@ -54,32 +55,40 @@ public EnhancedSession(PropertyHelper propertyHelper, CqlSession cqlSession, boo
public void setPKFactory(PKFactory pkFactory) {
this.pkFactory = pkFactory;
}
public PKFactory getPKFactory() { return this.pkFactory; }

public PKFactory getPKFactory() {
return this.pkFactory;
}

public CqlSession getCqlSession() {
return cqlSession;
}

public CqlTable getCqlTable() {
return cqlTable;
}

public OriginSelectByPartitionRangeStatement getOriginSelectByPartitionRangeStatement() {
if (!isOrigin) throw new RuntimeException("This is not an origin session");
if (!isOrigin)
throw new RuntimeException("This is not an origin session");
return new OriginSelectByPartitionRangeStatement(propertyHelper, this);
}

public OriginSelectByPKStatement getOriginSelectByPKStatement() {
if (!isOrigin) throw new RuntimeException("This is not an origin session");
if (!isOrigin)
throw new RuntimeException("This is not an origin session");
return new OriginSelectByPKStatement(propertyHelper, this);
}

public TargetSelectByPKStatement getTargetSelectByPKStatement() {
if (isOrigin) throw new RuntimeException("This is not a target session");
if (isOrigin)
throw new RuntimeException("This is not a target session");
return new TargetSelectByPKStatement(propertyHelper, this);
}

public TargetUpsertStatement getTargetUpsertStatement() {
if (isOrigin) throw new RuntimeException("This is not a target session");
if (isOrigin)
throw new RuntimeException("This is not a target session");
if (cqlTable.isCounterTable())
return new TargetUpdateStatement(propertyHelper, this);
else
Expand All @@ -88,15 +97,17 @@ public TargetUpsertStatement getTargetUpsertStatement() {

private CqlSession initSession(PropertyHelper propertyHelper, CqlSession session) {
List<String> codecList = propertyHelper.getStringList(KnownProperties.TRANSFORM_CODECS);
if (null!=codecList && !codecList.isEmpty()) {
if (null != codecList && !codecList.isEmpty()) {
MutableCodecRegistry registry = (MutableCodecRegistry) session.getContext().getCodecRegistry();

for (String codecString : codecList) {
Codecset codecEnum = Codecset.valueOf(codecString);
for (TypeCodec<?> codec : CodecFactory.getCodecPair(propertyHelper, codecEnum)) {
DataType dataType = codec.getCqlType();
GenericType<?> javaType = codec.getJavaType();
if (logDebug) logger.debug("Registering Codec {} for CQL type {} and Java type {}", codec.getClass().getSimpleName(), dataType, javaType);
if (logDebug)
logger.debug("Registering Codec {} for CQL type {} and Java type {}",
codec.getClass().getSimpleName(), dataType, javaType);
try {
registry.codecFor(dataType, javaType);
} catch (CodecNotFoundException e) {
Expand All @@ -108,6 +119,4 @@ private CqlSession initSession(PropertyHelper propertyHelper, CqlSession session
return session;
}



}
10 changes: 5 additions & 5 deletions src/main/java/com/datastax/cdm/cql/codec/BIGINT_StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package com.datastax.cdm.cql.codec;

import java.nio.ByteBuffer;

import org.jetbrains.annotations.NotNull;

import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import com.datastax.cdm.properties.PropertyHelper;
import org.jetbrains.annotations.NotNull;

import java.nio.ByteBuffer;

public class BIGINT_StringCodec extends AbstractBaseCodec<String> {

Expand Down Expand Up @@ -70,4 +71,3 @@ public String parse(String value) {
}

}

42 changes: 27 additions & 15 deletions src/main/java/com/datastax/cdm/cql/codec/CodecFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,44 @@
*/
package com.datastax.cdm.cql.codec;

import java.util.Arrays;
import java.util.List;

import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.dse.driver.internal.core.type.codec.geometry.LineStringCodec;
import com.datastax.dse.driver.internal.core.type.codec.geometry.PointCodec;
import com.datastax.dse.driver.internal.core.type.codec.geometry.PolygonCodec;
import com.datastax.dse.driver.internal.core.type.codec.time.DateRangeCodec;
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;

import java.util.Arrays;
import java.util.List;

public class CodecFactory {
public static List<TypeCodec<?>> getCodecPair(PropertyHelper propertyHelper, Codecset codec) {
switch (codec) {
case INT_STRING: return Arrays.asList(new INT_StringCodec(propertyHelper), new TEXT_IntegerCodec(propertyHelper));
case DOUBLE_STRING: return Arrays.asList(new DOUBLE_StringCodec(propertyHelper), new TEXT_DoubleCodec(propertyHelper));
case BIGINT_STRING: return Arrays.asList(new BIGINT_StringCodec(propertyHelper), new TEXT_LongCodec(propertyHelper));
case DECIMAL_STRING: return Arrays.asList(new DECIMAL_StringCodec(propertyHelper), new TEXT_BigDecimalCodec(propertyHelper));
case TIMESTAMP_STRING_MILLIS: return Arrays.asList(new TIMESTAMP_StringMillisCodec(propertyHelper), new TEXTMillis_InstantCodec(propertyHelper));
case TIMESTAMP_STRING_FORMAT: return Arrays.asList(new TIMESTAMP_StringFormatCodec(propertyHelper), new TEXTFormat_InstantCodec(propertyHelper));
case POLYGON_TYPE: return Arrays.asList(new PolygonCodec());
case POINT_TYPE: return Arrays.asList(new PointCodec());
case DATE_RANGE: return Arrays.asList(new DateRangeCodec());
case LINE_STRING: return Arrays.asList(new LineStringCodec());
case INT_STRING:
return Arrays.asList(new INT_StringCodec(propertyHelper), new TEXT_IntegerCodec(propertyHelper));
case DOUBLE_STRING:
return Arrays.asList(new DOUBLE_StringCodec(propertyHelper), new TEXT_DoubleCodec(propertyHelper));
case BIGINT_STRING:
return Arrays.asList(new BIGINT_StringCodec(propertyHelper), new TEXT_LongCodec(propertyHelper));
case DECIMAL_STRING:
return Arrays.asList(new DECIMAL_StringCodec(propertyHelper), new TEXT_BigDecimalCodec(propertyHelper));
case TIMESTAMP_STRING_MILLIS:
return Arrays.asList(new TIMESTAMP_StringMillisCodec(propertyHelper),
new TEXTMillis_InstantCodec(propertyHelper));
case TIMESTAMP_STRING_FORMAT:
return Arrays.asList(new TIMESTAMP_StringFormatCodec(propertyHelper),
new TEXTFormat_InstantCodec(propertyHelper));
case POLYGON_TYPE:
return Arrays.asList(new PolygonCodec());
case POINT_TYPE:
return Arrays.asList(new PointCodec());
case DATE_RANGE:
return Arrays.asList(new DateRangeCodec());
case LINE_STRING:
return Arrays.asList(new LineStringCodec());

default:
throw new IllegalArgumentException("Unknown codec: " + codec);
default:
throw new IllegalArgumentException("Unknown codec: " + codec);
}
}
}
12 changes: 2 additions & 10 deletions src/main/java/com/datastax/cdm/cql/codec/Codecset.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@
package com.datastax.cdm.cql.codec;

public enum Codecset {
INT_STRING,
DOUBLE_STRING,
BIGINT_STRING,
DECIMAL_STRING,
TIMESTAMP_STRING_MILLIS,
TIMESTAMP_STRING_FORMAT,
POINT_TYPE,
POLYGON_TYPE,
DATE_RANGE,
LINE_STRING
INT_STRING, DOUBLE_STRING, BIGINT_STRING, DECIMAL_STRING, TIMESTAMP_STRING_MILLIS, TIMESTAMP_STRING_FORMAT,
POINT_TYPE, POLYGON_TYPE, DATE_RANGE, LINE_STRING
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
*/
package com.datastax.cdm.cql.codec;

import java.math.BigDecimal;
import java.nio.ByteBuffer;

import org.jetbrains.annotations.NotNull;

import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.nio.ByteBuffer;

public class DECIMAL_StringCodec extends AbstractBaseCodec<String> {

Expand Down Expand Up @@ -70,4 +71,3 @@ public String parse(String value) {
return decimalValue == null ? null : decimalValue.toString();
}
}

11 changes: 6 additions & 5 deletions src/main/java/com/datastax/cdm/cql/codec/DOUBLE_StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
*/
package com.datastax.cdm.cql.codec;

import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;

import org.jetbrains.annotations.NotNull;

import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import org.jetbrains.annotations.NotNull;

import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;

// This works with decimal-formatted doubles in strings, but not
// with the default scientific notation. A separate codec is needed
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/datastax/cdm/cql/codec/INT_StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package com.datastax.cdm.cql.codec;

import java.nio.ByteBuffer;

import org.jetbrains.annotations.NotNull;

import com.datastax.cdm.properties.PropertyHelper;
import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import org.jetbrains.annotations.NotNull;

import java.nio.ByteBuffer;

public class INT_StringCodec extends AbstractBaseCodec<String> {

Expand Down Expand Up @@ -69,4 +70,3 @@ public String parse(String value) {
return intValue == null ? null : intValue.toString();
}
}

Loading

0 comments on commit f079698

Please sign in to comment.