MartijnVisser commented on code in PR #53:
URL:
https://github.com/apache/flink-connector-cassandra/pull/53#discussion_r4604148602
##########
pom.xml:
##########
@@ -54,27 +53,13 @@ under the License.
<dependencyManagement>
<dependencies>
- <!-- For dependency convergence -->
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>${guava.version}</version>
- </dependency>
-
<!-- For dependency convergence -->
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.10.4</version>
</dependency>
- <!-- For dependency convergence -->
- <dependency>
- <groupId>io.dropwizard.metrics</groupId>
- <artifactId>metrics-core</artifactId>
Review Comment:
CI fails on dependency convergence. Pinning `metrics-core` 4.1.18 and
`jsr305` 1.3.9 here fixes it, I checked with `-Pcheck-convergence` on 1.20.5.
##########
flink-connector-cassandra/src/main/java/org/apache/flink/streaming/connectors/cassandra/CassandraSessionBuilder.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.cassandra;
Review Comment:
I think this and `CassandraMapperOptions` should move to
`org.apache.flink.connector.cassandra` while we're breaking anyway, next to the
source and the Sink V2 sink.
##########
flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/source/utils/CassandraUtils.java:
##########
@@ -18,24 +18,47 @@
package org.apache.flink.connector.cassandra.source.utils;
-import com.datastax.driver.core.ColumnMetadata;
-import com.datastax.driver.core.Metadata;
+import com.datastax.oss.driver.api.core.metadata.Metadata;
+import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
-import java.util.Set;
+import java.util.List;
import java.util.stream.Collectors;
/** Common utilities for Cassandra related tasks. */
public class CassandraUtils {
+ /**
+ * Returns the partition key columns formatted to be used in a CQL query,
in the order of the
+ * partition key. The names of the case-sensitive columns are
double-quoted.
+ */
public static String getPartitionKeyString(
Review Comment:
Both cases fail on main with `InvalidQueryException`, so I've filed
FLINK-41537 for a v3.3 backport. Can you move this fix to a separate commit for
that ticket? Through SQL a quoted key still fails on a 2.3 cluster, the select
list in `CassandraTableFactory` isn't quoted.
##########
flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/mapper/PojoMapper.java:
##########
@@ -0,0 +1,533 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.cassandra.mapper;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.streaming.connectors.cassandra.CassandraMapperOptions;
+import org.apache.flink.util.FlinkRuntimeException;
+import org.apache.flink.util.Preconditions;
+
+import com.datastax.oss.driver.api.core.CqlIdentifier;
+import com.datastax.oss.driver.api.core.cql.BoundStatement;
+import com.datastax.oss.driver.api.core.cql.BoundStatementBuilder;
+import com.datastax.oss.driver.api.core.cql.PreparedStatement;
+import com.datastax.oss.driver.api.core.cql.Row;
+import com.datastax.oss.driver.api.core.cql.SimpleStatement;
+import com.datastax.oss.driver.api.core.data.GettableById;
+import com.datastax.oss.driver.api.core.data.UdtValue;
+import com.datastax.oss.driver.api.core.type.DataType;
+import com.datastax.oss.driver.api.core.type.UserDefinedType;
+import com.datastax.oss.driver.api.core.type.reflect.GenericType;
+import com.datastax.oss.driver.api.mapper.annotations.Computed;
+import com.datastax.oss.driver.api.mapper.annotations.CqlName;
+import com.datastax.oss.driver.api.mapper.annotations.Entity;
+import com.datastax.oss.driver.api.mapper.annotations.NamingStrategy;
+import com.datastax.oss.driver.api.mapper.annotations.Transient;
+import com.datastax.oss.driver.api.mapper.annotations.TransientProperties;
+import com.datastax.oss.driver.api.mapper.entity.naming.NameConverter;
+import com.datastax.oss.driver.api.mapper.entity.naming.NamingConvention;
+import com.datastax.oss.driver.api.querybuilder.QueryBuilder;
+import com.datastax.oss.driver.api.querybuilder.insert.Insert;
+import com.datastax.oss.driver.api.querybuilder.insert.InsertInto;
+import com.datastax.oss.driver.api.querybuilder.insert.RegularInsert;
+
+import javax.annotation.Nullable;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+/**
+ * Maps POJOs annotated with {@link Entity} to and from Cassandra at runtime.
+ *
+ * <p>The mapper of the Cassandra driver generates its code with an annotation
processor at compile
+ * time, so it cannot map a class that is only known at runtime. This class
supports the subset of
+ * the driver mapper annotations that the connector needs: {@link Entity},
{@link CqlName}, {@link
+ * NamingStrategy}, {@link Transient}, {@link TransientProperties} and {@link
Computed}. A property
+ * whose type is itself annotated with {@link Entity} is mapped to a user
defined type.
+ *
+ * @param <T> the type of the mapped POJO
+ */
+@Internal
+public final class PojoMapper<T> {
+
+ private final Class<T> pojoClass;
+ @Nullable private final CqlIdentifier keyspace;
+ private final CqlIdentifier table;
+ private final List<Property> properties;
+ private final List<Property> writableProperties;
+
+ private PojoMapper(
+ Class<T> pojoClass,
+ @Nullable CqlIdentifier keyspace,
+ CqlIdentifier table,
+ List<Property> properties) {
+ this.pojoClass = pojoClass;
+ this.keyspace = keyspace;
+ this.table = table;
+ this.properties = properties;
+ this.writableProperties =
+ properties.stream().filter(p ->
!p.computed).collect(Collectors.toList());
+ }
+
+ /**
+ * Creates the mapper of a class annotated with {@link Entity}.
+ *
+ * @param pojoClass the class to map
+ * @param <T> the type of the mapped POJO
+ * @return the mapper
+ */
+ public static <T> PojoMapper<T> create(Class<T> pojoClass) {
Review Comment:
Naming and transients match the driver's generated code for the entities I
tried, but `@HierarchyScanStrategy` is silently ignored and `@PropertyStrategy`
fails with a misleading error. Please reject unsupported mapper annotations by
name.
##########
flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/source/enumerator/CassandraSplitEnumerator.java:
##########
@@ -44,24 +44,22 @@ public final class CassandraSplitEnumerator
private final SplitEnumeratorContext<CassandraSplit> enumeratorContext;
private CassandraEnumeratorState state;
- private final Cluster cluster;
private final Long maxSplitMemorySize;
- private final Session session;
+ private final CqlSession session;
private final String keyspace;
private final String table;
public CassandraSplitEnumerator(
SplitEnumeratorContext<CassandraSplit> enumeratorContext,
CassandraEnumeratorState state,
- ClusterBuilder clusterBuilder,
+ CassandraSessionBuilder sessionBuilder,
Long maxSplitMemorySize,
String keyspace,
String table) {
this.enumeratorContext = enumeratorContext;
this.state = state == null ? new CassandraEnumeratorState() : state /*
snapshot restore*/;
- this.cluster = clusterBuilder.getCluster();
this.maxSplitMemorySize = maxSplitMemorySize;
- this.session = cluster.newSession();
+ this.session = sessionBuilder.getSession();
Review Comment:
`getSession()` connects, where `cluster.newSession()` didn't, and this runs
on the coordinator thread. Can you open the session in `prepareSplits` instead?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]