echauchot commented on code in PR #3: URL: https://github.com/apache/flink-connector-cassandra/pull/3#discussion_r1086431597
########## flink-connector-cassandra/src/main/java/org/apache/flink/connector/cassandra/source/reader/CassandraRecordEmitter.java: ########## @@ -0,0 +1,154 @@ +/* + * 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.source.reader; + +import org.apache.flink.api.connector.source.SourceOutput; +import org.apache.flink.connector.base.source.reader.RecordEmitter; +import org.apache.flink.connector.cassandra.source.split.CassandraSplitState; +import org.apache.flink.streaming.connectors.cassandra.ClusterBuilder; +import org.apache.flink.streaming.connectors.cassandra.MapperOptions; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.ColumnDefinitions; +import com.datastax.driver.core.ExecutionInfo; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.MappingManager; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * {@link RecordEmitter} that converts the {@link CassandraRow} read by the {@link + * CassandraSplitReader} to specified POJO and output it while updating splits state. This class + * uses the Cassandra driver mapper to map the row to the POJO. + * + * @param <OUT> type of POJO record to output + */ +public class CassandraRecordEmitter<OUT> + implements RecordEmitter<CassandraRow, OUT, CassandraSplitState> { + + private final Mapper<OUT> mapper; + + public CassandraRecordEmitter( + Class<OUT> pojoClass, ClusterBuilder clusterBuilder, MapperOptions mapperOptions) { + // session and cluster are managed at the SplitReader level. So we need to create one + // locally here just to me able to create the mapper. + final Cluster cluster = clusterBuilder.getCluster(); + final Session session = cluster.connect(); Review Comment: Well, mapping from row to pojo is rather complex and is supported out of the box by Cassandra mapper. Would not it be easier for the user if we guide him in using the mapper rather than leaving him provide a potentially buggy mapping function ? I agree, crating the cluster and session here just for mapper creation is sketchy but I cannot get them in `CassandraRecordEmitter` from the `CassandraSplitReader`. WDYT ? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org