You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ma...@apache.org on 2024/05/14 07:00:57 UTC
(flink-connector-kudu) 38/44: [FLINK-34930] Apply spotless code format and checkstyle rules
This is an automated email from the ASF dual-hosted git repository.
martijnvisser pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-connector-kudu.git
commit abf6eba5902660ed6df6a2bd1fcf8b89ccb65f53
Author: Ferenc Csaky <fe...@pm.me>
AuthorDate: Thu Mar 28 12:46:36 2024 +0100
[FLINK-34930] Apply spotless code format and checkstyle rules
---
.../kudu/connector/ColumnSchemasFactory.java | 10 +-
.../kudu/connector/CreateTableOptionsFactory.java | 10 +-
.../connectors/kudu/connector/KuduFilterInfo.java | 49 +++-
.../connectors/kudu/connector/KuduTableInfo.java | 56 ++--
.../RowResultConverter.java} | 14 +-
.../RowResultRowConverter.java} | 30 ++-
.../converter/RowResultRowDataConverter.java | 104 ++++++++
.../convertor/RowResultRowDataConvertor.java | 84 ------
.../failure/DefaultKuduFailureHandler.java | 13 +-
.../kudu/connector/failure/KuduFailureHandler.java | 11 +-
.../kudu/connector/reader/KuduInputSplit.java | 10 +-
.../kudu/connector/reader/KuduReader.java | 82 +++---
.../kudu/connector/reader/KuduReaderConfig.java | 19 +-
.../kudu/connector/reader/KuduReaderIterator.java | 14 +-
.../writer/AbstractSingleOperationMapper.java | 23 +-
.../kudu/connector/writer/KuduOperationMapper.java | 12 +-
.../kudu/connector/writer/KuduWriter.java | 31 ++-
.../kudu/connector/writer/KuduWriterConfig.java | 13 +-
.../kudu/connector/writer/PojoOperationMapper.java | 28 +-
.../writer/RowDataUpsertOperationMapper.java | 61 +++--
.../kudu/connector/writer/RowOperationMapper.java | 2 +
.../connector/writer/TupleOperationMapper.java | 2 +
.../kudu/format/AbstractKuduInputFormat.java | 57 ++--
.../connectors/kudu/format/KuduOutputFormat.java | 25 +-
.../kudu/format/KuduRowDataInputFormat.java | 30 ++-
.../connectors/kudu/format/KuduRowInputFormat.java | 35 ++-
.../flink/connectors/kudu/streaming/KuduSink.java | 49 ++--
.../kudu/table/AbstractReadOnlyCatalog.java | 109 ++++++--
.../flink/connectors/kudu/table/KuduCatalog.java | 120 ++++++---
.../connectors/kudu/table/KuduTableFactory.java | 47 +++-
.../flink/connectors/kudu/table/KuduTableSink.java | 41 ++-
.../connectors/kudu/table/KuduTableSource.java | 108 +++++---
.../kudu/table/UpsertOperationMapper.java | 3 +
.../kudu/table/dynamic/KuduDynamicTableSink.java | 42 ++-
.../kudu/table/dynamic/KuduDynamicTableSource.java | 116 ++++++---
.../dynamic/KuduDynamicTableSourceSinkFactory.java | 146 +++++------
.../table/dynamic/catalog/KuduCatalogFactory.java | 10 +-
.../table/dynamic/catalog/KuduDynamicCatalog.java | 134 +++++++---
.../table/function/lookup/KuduLookupOptions.java | 9 +-
.../function/lookup/KuduRowDataLookupFunction.java | 64 ++---
.../kudu/table/utils/KuduTableUtils.java | 164 +++++++-----
.../connectors/kudu/table/utils/KuduTypeUtils.java | 20 +-
.../kudu/connector/KuduFilterInfoTest.java | 10 +-
.../connectors/kudu/connector/KuduTestBase.java | 289 ++++++++++++---------
.../kudu/format/KuduOutputFormatTest.java | 53 ++--
.../kudu/format/KuduRowDataInputFormatTest.java | 51 ++--
.../kudu/format/KuduRowInputFormatTest.java | 32 ++-
.../connectors/kudu/streaming/KuduSinkTest.java | 118 ++++++---
.../connectors/kudu/table/KuduCatalogTest.java | 158 ++++++-----
.../kudu/table/KuduTableFactoryTest.java | 106 +++++---
.../kudu/table/KuduTableSourceITCase.java | 17 +-
.../connectors/kudu/table/KuduTableSourceTest.java | 98 ++++---
.../connectors/kudu/table/KuduTableTestUtils.java | 13 +-
.../kudu/table/dynamic/KuduDynamicSinkTest.java | 54 ++--
.../kudu/table/dynamic/KuduDynamicSourceTest.java | 37 +--
.../dynamic/KuduRowDataLookupFunctionTest.java | 45 ++--
.../kudu/writer/AbstractOperationTest.java | 33 +--
.../kudu/writer/PojoOperationMapperTest.java | 14 +-
.../writer/RowDataUpsertOperationMapperTest.java | 7 +-
.../kudu/writer/RowOperationMapperTest.java | 15 +-
...pperTest.java => TupleOperationMapperTest.java} | 23 +-
61 files changed, 1979 insertions(+), 1201 deletions(-)
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/ColumnSchemasFactory.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/ColumnSchemasFactory.java
index 4997938..194af17 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/ColumnSchemasFactory.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/ColumnSchemasFactory.java
@@ -18,17 +18,18 @@
package org.apache.flink.connectors.kudu.connector;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.ColumnSchema;
import java.io.Serializable;
import java.util.List;
/**
- * Factory for creating {@link ColumnSchema}s to be used when creating a table that
- * does not currently exist in Kudu. Usable through {@link KuduTableInfo#createTableIfNotExists}.
+ * Factory for creating {@link ColumnSchema}s to be used when creating a table that does not
+ * currently exist in Kudu. Usable through {@link KuduTableInfo#createTableIfNotExists}.
*
- * <p> This factory implementation must be Serializable as it will be used directly in the Flink sources
- * and sinks.
+ * <p>This factory implementation must be Serializable as it will be used directly in the Flink
+ * sources and sinks.
*/
@PublicEvolving
public interface ColumnSchemasFactory extends Serializable {
@@ -39,5 +40,4 @@ public interface ColumnSchemasFactory extends Serializable {
* @return List of columns.
*/
List<ColumnSchema> getColumnSchemas();
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/CreateTableOptionsFactory.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/CreateTableOptionsFactory.java
index fd9bfa4..31aa735 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/CreateTableOptionsFactory.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/CreateTableOptionsFactory.java
@@ -18,16 +18,17 @@
package org.apache.flink.connectors.kudu.connector;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.client.CreateTableOptions;
import java.io.Serializable;
/**
- * Factory for creating {@link CreateTableOptions} to be used when creating a table that
- * does not currently exist in Kudu. Usable through {@link KuduTableInfo#createTableIfNotExists}.
+ * Factory for creating {@link CreateTableOptions} to be used when creating a table that does not
+ * currently exist in Kudu. Usable through {@link KuduTableInfo#createTableIfNotExists}.
*
- * <p> This factory implementation must be Serializable as it will be used directly in the Flink sources
- * and sinks.
+ * <p>This factory implementation must be Serializable as it will be used directly in the Flink
+ * sources and sinks.
*/
@PublicEvolving
public interface CreateTableOptionsFactory extends Serializable {
@@ -38,5 +39,4 @@ public interface CreateTableOptionsFactory extends Serializable {
* @return CreateTableOptions for creating the table.
*/
CreateTableOptions getCreateTableOptions();
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfo.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfo.java
index 94e2e26..828efff 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfo.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfo.java
@@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.table.data.binary.BinaryStringData;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.client.KuduPredicate;
@@ -25,6 +27,7 @@ import org.apache.kudu.client.KuduPredicate;
import java.io.Serializable;
import java.util.List;
+/** Helper class that groups necessary data to define a Kudu column filter. */
@PublicEvolving
public class KuduFilterInfo implements Serializable {
@@ -32,7 +35,7 @@ public class KuduFilterInfo implements Serializable {
private FilterType type;
private Object value;
- private KuduFilterInfo() { }
+ private KuduFilterInfo() {}
public KuduPredicate toPredicate(Schema schema) {
return toPredicate(schema.getColumn(this.column));
@@ -65,36 +68,54 @@ public class KuduFilterInfo implements Serializable {
switch (column.getType()) {
case STRING:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison,
- (this.value instanceof BinaryStringData) ? this.value.toString() : (String) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column,
+ comparison,
+ (this.value instanceof BinaryStringData)
+ ? this.value.toString()
+ : (String) this.value);
break;
case FLOAT:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (float) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column, comparison, (float) this.value);
break;
case INT8:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (byte) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(column, comparison, (byte) this.value);
break;
case INT16:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (short) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column, comparison, (short) this.value);
break;
case INT32:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (int) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(column, comparison, (int) this.value);
break;
case INT64:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (long) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(column, comparison, (long) this.value);
break;
case DOUBLE:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (double) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column, comparison, (double) this.value);
break;
case BOOL:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (boolean) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column, comparison, (boolean) this.value);
break;
case UNIXTIME_MICROS:
Long time = (Long) this.value;
predicate = KuduPredicate.newComparisonPredicate(column, comparison, time * 1000);
break;
case BINARY:
- predicate = KuduPredicate.newComparisonPredicate(column, comparison, (byte[]) this.value);
+ predicate =
+ KuduPredicate.newComparisonPredicate(
+ column, comparison, (byte[]) this.value);
break;
default:
throw new IllegalArgumentException("Illegal var type: " + column.getType());
@@ -102,6 +123,7 @@ public class KuduFilterInfo implements Serializable {
return predicate;
}
+ /** Possible filter types and their appropriate Kudu comparison operator. */
public enum FilterType {
GREATER(KuduPredicate.ComparisonOp.GREATER),
GREATER_EQUAL(KuduPredicate.ComparisonOp.GREATER_EQUAL),
@@ -117,11 +139,11 @@ public class KuduFilterInfo implements Serializable {
FilterType(KuduPredicate.ComparisonOp comparator) {
this.comparator = comparator;
}
-
}
+ /** KuduFilterInfo builder. */
public static class Builder {
- private KuduFilterInfo filter;
+ private final KuduFilterInfo filter;
private Builder(String column) {
this.filter = new KuduFilterInfo();
@@ -174,5 +196,4 @@ public class KuduFilterInfo implements Serializable {
return filter;
}
}
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduTableInfo.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduTableInfo.java
index 655a914..53dba54 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduTableInfo.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/KuduTableInfo.java
@@ -14,23 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector;
-import org.apache.commons.lang3.Validate;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.Schema;
import org.apache.kudu.client.CreateTableOptions;
import java.io.Serializable;
import java.util.Objects;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
/**
- * Describes which table should be used in sources and sinks along with specifications
- * on how to create it if it does not exist.
+ * Describes which table should be used in sources and sinks along with specifications on how to
+ * create it if it does not exist.
*
- * <p> For sources and sinks reading from already existing tables, simply use @{@link KuduTableInfo#forTable(String)}
- * and if you want the system to create the table if it does not exist you need to specify the column and options
- * factories through {@link KuduTableInfo#createTableIfNotExists}
+ * <p>For sources and sinks reading from already existing tables, simply use @{@link
+ * KuduTableInfo#forTable(String)} and if you want the system to create the table if it does not
+ * exist you need to specify the column and options factories through {@link
+ * KuduTableInfo#createTableIfNotExists}
*/
@PublicEvolving
public class KuduTableInfo implements Serializable {
@@ -40,12 +44,12 @@ public class KuduTableInfo implements Serializable {
private ColumnSchemasFactory schemasFactory = null;
private KuduTableInfo(String name) {
- this.name = Validate.notNull(name);
+ this.name = checkNotNull(name);
}
/**
- * Creates a new {@link KuduTableInfo} that is sufficient for reading/writing to existing Kudu Tables.
- * For creating new tables call {@link #createTableIfNotExists} afterwards.
+ * Creates a new {@link KuduTableInfo} that is sufficient for reading/writing to existing Kudu
+ * Tables. For creating new tables call {@link #createTableIfNotExists} afterward.
*
* @param name Table name in Kudu
* @return KuduTableInfo for the given table name
@@ -55,51 +59,51 @@ public class KuduTableInfo implements Serializable {
}
/**
- * Defines table parameters to be used when creating the Kudu table if it does not exist (read or write)
+ * Defines table parameters to be used when creating the Kudu table if it does not exist (read
+ * or write).
*
- * @param schemasFactory factory for defining columns
+ * @param schemasFactory factory for defining columns
* @param createTableOptionsFactory factory for defining create table options
* @return KuduTableInfo that will create tables that does not exist with the given settings.
*/
- public KuduTableInfo createTableIfNotExists(ColumnSchemasFactory schemasFactory, CreateTableOptionsFactory createTableOptionsFactory) {
- this.createTableOptionsFactory = Validate.notNull(createTableOptionsFactory);
- this.schemasFactory = Validate.notNull(schemasFactory);
+ public KuduTableInfo createTableIfNotExists(
+ ColumnSchemasFactory schemasFactory,
+ CreateTableOptionsFactory createTableOptionsFactory) {
+ this.createTableOptionsFactory = checkNotNull(createTableOptionsFactory);
+ this.schemasFactory = checkNotNull(schemasFactory);
return this;
}
/**
- * Returns the {@link Schema} of the table. Only works if {@link #createTableIfNotExists} was specified otherwise throws an error.
+ * Returns the {@link Schema} of the table. Only works if {@link #createTableIfNotExists} was
+ * specified otherwise throws an error.
*
* @return Schema of the target table.
*/
public Schema getSchema() {
if (!getCreateTableIfNotExists()) {
- throw new RuntimeException("Cannot access schema for KuduTableInfo. Use createTableIfNotExists to specify the columns.");
+ throw new RuntimeException(
+ "Cannot access schema for KuduTableInfo. Use createTableIfNotExists to specify the columns.");
}
return new Schema(schemasFactory.getColumnSchemas());
}
- /**
- * @return Name of the table.
- */
+ /** @return Name of the table. */
public String getName() {
return name;
}
- /**
- * @return True if table creation is enabled if target table does not exist.
- */
+ /** @return True if table creation is enabled if target table does not exist. */
public boolean getCreateTableIfNotExists() {
return createTableOptionsFactory != null;
}
- /**
- * @return CreateTableOptions if {@link #createTableIfNotExists} was specified.
- */
+ /** @return CreateTableOptions if {@link #createTableIfNotExists} was specified. */
public CreateTableOptions getCreateTableOptions() {
if (!getCreateTableIfNotExists()) {
- throw new RuntimeException("Cannot access CreateTableOptions for KuduTableInfo. Use createTableIfNotExists to specify.");
+ throw new RuntimeException(
+ "Cannot access CreateTableOptions for KuduTableInfo. Use createTableIfNotExists to specify.");
}
return createTableOptionsFactory.getCreateTableOptions();
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultConvertor.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultConverter.java
similarity index 74%
rename from flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultConvertor.java
rename to flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultConverter.java
index 2cbb97e..c2f4bfc 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultConvertor.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultConverter.java
@@ -14,26 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.flink.connectors.kudu.connector.convertor;
+
+package org.apache.flink.connectors.kudu.connector.converter;
import org.apache.flink.annotation.Internal;
+
import org.apache.kudu.client.RowResult;
import java.io.Serializable;
/**
- * The RowResult object of Kudu is converted to correspond to the Flink internal row object
+ * Interface to convert Kudu RowResult objects to internal Flink row representations.
*
- * @param <T> Kudu rowResult Convertor format
+ * @param <T> Target Flink representation type
*/
@Internal
-public interface RowResultConvertor<T> extends Serializable {
+public interface RowResultConverter<T> extends Serializable {
/**
- * Convert Kudu RowResult to the corresponding format
+ * Convert Kudu RowResult to the corresponding format.
*
* @param row Kudu RowResult Type
* @return {@link T}
*/
- T convertor(RowResult row);
+ T convert(RowResult row);
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowConvertor.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowConverter.java
similarity index 62%
rename from flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowConvertor.java
rename to flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowConverter.java
index b6f4eee..f1f1b87 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowConvertor.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowConverter.java
@@ -14,31 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.flink.connectors.kudu.connector.convertor;
+
+package org.apache.flink.connectors.kudu.connector.converter;
import org.apache.flink.annotation.Internal;
import org.apache.flink.types.Row;
+
import org.apache.kudu.Schema;
import org.apache.kudu.client.RowResult;
-/**
- * Transform the Kudu RowResult object into a Flink Row object
- */
+/** Transforms a Kudu RowResult object into a Flink Row object. */
@Internal
-public class RowResultRowConvertor implements RowResultConvertor<Row> {
+public class RowResultRowConverter implements RowResultConverter<Row> {
@Override
- public Row convertor(RowResult row) {
+ public Row convert(RowResult row) {
Schema schema = row.getColumnProjection();
Row values = new Row(schema.getColumnCount());
- schema.getColumns().forEach(column -> {
- String name = column.getName();
- int pos = schema.getColumnIndex(name);
- if (row.isNull(name)) {
- return;
- }
- values.setField(pos, row.getObject(name));
- });
+ schema.getColumns()
+ .forEach(
+ column -> {
+ String name = column.getName();
+ int pos = schema.getColumnIndex(name);
+ if (row.isNull(name)) {
+ return;
+ }
+ values.setField(pos, row.getObject(name));
+ });
return values;
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowDataConverter.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowDataConverter.java
new file mode 100644
index 0000000..033ec04
--- /dev/null
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/converter/RowResultRowDataConverter.java
@@ -0,0 +1,104 @@
+/*
+ * 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.connectors.kudu.connector.converter;
+
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.data.TimestampData;
+
+import org.apache.kudu.Schema;
+import org.apache.kudu.Type;
+import org.apache.kudu.client.RowResult;
+
+import java.math.BigDecimal;
+import java.util.Objects;
+
+/** Transforms a Kudu RowResult object into a Flink RowData object. */
+public class RowResultRowDataConverter implements RowResultConverter<RowData> {
+ @Override
+ public RowData convert(RowResult row) {
+ Schema schema = row.getColumnProjection();
+ GenericRowData values = new GenericRowData(schema.getColumnCount());
+ schema.getColumns()
+ .forEach(
+ column -> {
+ String name = column.getName();
+ Type type = column.getType();
+ int pos = schema.getColumnIndex(name);
+ if (Objects.isNull(type)) {
+ throw new IllegalArgumentException("columnName:" + name);
+ }
+ if (row.isNull(name)) {
+ return;
+ }
+ switch (type) {
+ case DECIMAL:
+ BigDecimal decimal = row.getDecimal(name);
+ values.setField(
+ pos,
+ DecimalData.fromBigDecimal(
+ decimal, decimal.precision(), decimal.scale()));
+ break;
+ case UNIXTIME_MICROS:
+ values.setField(
+ pos,
+ TimestampData.fromTimestamp(row.getTimestamp(name)));
+ break;
+ case DOUBLE:
+ values.setField(pos, row.getDouble(name));
+ break;
+ case STRING:
+ Object value = row.getObject(name);
+ values.setField(
+ pos,
+ StringData.fromString(
+ Objects.nonNull(value)
+ ? value.toString()
+ : ""));
+ break;
+ case BINARY:
+ values.setField(pos, row.getBinary(name));
+ break;
+ case FLOAT:
+ values.setField(pos, row.getFloat(name));
+ break;
+ case INT64:
+ values.setField(pos, row.getLong(name));
+ break;
+ case INT32:
+ case INT16:
+ case INT8:
+ values.setField(pos, row.getInt(name));
+ break;
+ case BOOL:
+ values.setField(pos, row.getBoolean(name));
+ break;
+ default:
+ throw new IllegalArgumentException(
+ "columnName:"
+ + name
+ + ",type:"
+ + type.getName()
+ + "not support!");
+ }
+ });
+ return values;
+ }
+}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowDataConvertor.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowDataConvertor.java
deleted file mode 100644
index 5196d7f..0000000
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/convertor/RowResultRowDataConvertor.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.connectors.kudu.connector.convertor;
-
-import org.apache.flink.table.data.*;
-import org.apache.kudu.Schema;
-import org.apache.kudu.Type;
-import org.apache.kudu.client.RowResult;
-
-import java.math.BigDecimal;
-import java.util.Objects;
-
-/**
- * Transform the Kudu RowResult object into a Flink RowData object
- */
-public class RowResultRowDataConvertor implements RowResultConvertor<RowData> {
- @Override
- public RowData convertor(RowResult row) {
- Schema schema = row.getColumnProjection();
- GenericRowData values = new GenericRowData(schema.getColumnCount());
- schema.getColumns().forEach(column -> {
- String name = column.getName();
- Type type = column.getType();
- int pos = schema.getColumnIndex(name);
- if (Objects.isNull(type)) {
- throw new IllegalArgumentException("columnName:" + name);
- }
- if (row.isNull(name)){
- return;
- }
- switch (type) {
- case DECIMAL:
- BigDecimal decimal = row.getDecimal(name);
- values.setField(pos, DecimalData.fromBigDecimal(decimal, decimal.precision(), decimal.scale()));
- break;
- case UNIXTIME_MICROS:
- values.setField(pos, TimestampData.fromTimestamp(row.getTimestamp(name)));
- break;
- case DOUBLE:
- values.setField(pos, row.getDouble(name));
- break;
- case STRING:
- Object value = row.getObject(name);
- values.setField(pos, StringData.fromString(Objects.nonNull(value) ? value.toString() : ""));
- break;
- case BINARY:
- values.setField(pos, row.getBinary(name));
- break;
- case FLOAT:
- values.setField(pos, row.getFloat(name));
- break;
- case INT64:
- values.setField(pos, row.getLong(name));
- break;
- case INT32:
- case INT16:
- case INT8:
- values.setField(pos, row.getInt(name));
- break;
- case BOOL:
- values.setField(pos, row.getBoolean(name));
- break;
- default:
- throw new IllegalArgumentException("columnName:" + name + ",type:" + type.getName() + "not support!");
- }
- });
- return values;
- }
-}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/DefaultKuduFailureHandler.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/DefaultKuduFailureHandler.java
index 5f45137..99a636d 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/DefaultKuduFailureHandler.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/DefaultKuduFailureHandler.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.failure;
import org.apache.kudu.client.RowError;
@@ -22,17 +23,15 @@ import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
-/**
- * Default failure handling logic that doesn't do any handling but throws
- * an error.
- */
+/** Default failure handling logic that doesn't do any handling but throws an error. */
public class DefaultKuduFailureHandler implements KuduFailureHandler {
@Override
public void onFailure(List<RowError> failure) throws IOException {
- String errors = failure.stream()
- .map(error -> error.toString() + System.lineSeparator())
- .collect(Collectors.joining());
+ String errors =
+ failure.stream()
+ .map(error -> error.toString() + System.lineSeparator())
+ .collect(Collectors.joining());
throw new IOException("Error while sending value. \n " + errors);
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/KuduFailureHandler.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/KuduFailureHandler.java
index c67c6ed..ed1bc33 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/KuduFailureHandler.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/failure/KuduFailureHandler.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.failure;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.client.RowError;
import java.io.IOException;
@@ -24,17 +26,18 @@ import java.io.Serializable;
import java.util.List;
/**
- * Custom handling logic for errors resulting from trying to execute Kudu operations in the
- * {@link org.apache.flink.connectors.kudu.connector.writer.KuduWriter}
+ * Custom handling logic for errors resulting from trying to execute Kudu operations in the {@link
+ * org.apache.flink.connectors.kudu.connector.writer.KuduWriter}.
*/
@PublicEvolving
public interface KuduFailureHandler extends Serializable {
/**
- * Handle a failed {@link List<RowError>}.
+ * Handle a failure.
*
* @param failure the cause of failure
- * @throws IOException if the sink should fail on this failure, the implementation should rethrow the throwable or a custom one
+ * @throws IOException if the sink should fail on this failure, the implementation should
+ * rethrow the throwable or a custom one
*/
void onFailure(List<RowError> failure) throws IOException;
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduInputSplit.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduInputSplit.java
index 5d85d6c..8cc8b06 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduInputSplit.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduInputSplit.java
@@ -14,21 +14,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.reader;
import org.apache.flink.annotation.Internal;
import org.apache.flink.core.io.LocatableInputSplit;
+/** Kudu input split that holds a scan token to identify the split position. */
@Internal
public class KuduInputSplit extends LocatableInputSplit {
- private byte[] scanToken;
+ private static final long serialVersionUID = 1L;
+
+ private final byte[] scanToken;
/**
- * Creates a new KuduInputSplit
+ * Creates a new KuduInputSplit.
*
* @param splitNumber the number of the input split
- * @param hostnames The names of the hosts storing the data this input split refers to.
+ * @param hostnames the names of the hosts storing the data this input split refers to
*/
public KuduInputSplit(byte[] scanToken, final int splitNumber, final String[] hostnames) {
super(splitNumber, hostnames);
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReader.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReader.java
index 72b734c..9ff2f22 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReader.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReader.java
@@ -14,14 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.reader;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.flink.annotation.Internal;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
-import org.apache.kudu.client.*;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduException;
+import org.apache.kudu.client.KuduScanToken;
+import org.apache.kudu.client.KuduSession;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.client.LocatedTablet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,6 +36,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+/** Reader to read data from a Kudu table. */
@Internal
public class KuduReader<T> implements AutoCloseable {
@@ -38,26 +46,41 @@ public class KuduReader<T> implements AutoCloseable {
private final KuduReaderConfig readerConfig;
private List<KuduFilterInfo> tableFilters;
private List<String> tableProjections;
- private final RowResultConvertor<T> rowResultConvertor;
+ private final RowResultConverter<T> rowResultConverter;
private final transient KuduClient client;
private final transient KuduSession session;
private final transient KuduTable table;
- public KuduReader(KuduTableInfo tableInfo, KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor) throws IOException {
- this(tableInfo, readerConfig, rowResultConvertor, new ArrayList<>(), null);
+ public KuduReader(
+ KuduTableInfo tableInfo,
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter)
+ throws IOException {
+ this(tableInfo, readerConfig, rowResultConverter, new ArrayList<>(), null);
}
- public KuduReader(KuduTableInfo tableInfo, KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor, List<KuduFilterInfo> tableFilters) throws IOException {
- this(tableInfo, readerConfig, rowResultConvertor, tableFilters, null);
+ public KuduReader(
+ KuduTableInfo tableInfo,
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter,
+ List<KuduFilterInfo> tableFilters)
+ throws IOException {
+ this(tableInfo, readerConfig, rowResultConverter, tableFilters, null);
}
- public KuduReader(KuduTableInfo tableInfo, KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor, List<KuduFilterInfo> tableFilters, List<String> tableProjections) throws IOException {
+ public KuduReader(
+ KuduTableInfo tableInfo,
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter,
+ List<KuduFilterInfo> tableFilters,
+ List<String> tableProjections)
+ throws IOException {
this.tableInfo = tableInfo;
this.readerConfig = readerConfig;
this.tableFilters = tableFilters;
this.tableProjections = tableProjections;
- this.rowResultConvertor = rowResultConvertor;
+ this.rowResultConverter = rowResultConverter;
this.client = obtainClient();
this.session = obtainSession();
this.table = obtainTable();
@@ -72,8 +95,7 @@ public class KuduReader<T> implements AutoCloseable {
}
private KuduClient obtainClient() {
- return new KuduClient.KuduClientBuilder(readerConfig.getMasters())
- .build();
+ return new KuduClient.KuduClientBuilder(readerConfig.getMasters()).build();
}
private KuduSession obtainSession() {
@@ -86,16 +108,19 @@ public class KuduReader<T> implements AutoCloseable {
return client.openTable(tableName);
}
if (tableInfo.getCreateTableIfNotExists()) {
- return client.createTable(tableName, tableInfo.getSchema(), tableInfo.getCreateTableOptions());
+ return client.createTable(
+ tableName, tableInfo.getSchema(), tableInfo.getCreateTableOptions());
}
throw new RuntimeException("Table " + tableName + " does not exist.");
}
public KuduReaderIterator<T> scanner(byte[] token) throws IOException {
- return new KuduReaderIterator<>(KuduScanToken.deserializeIntoScanner(token, client), rowResultConvertor);
+ return new KuduReaderIterator<>(
+ KuduScanToken.deserializeIntoScanner(token, client), rowResultConverter);
}
- public List<KuduScanToken> scanTokens(List<KuduFilterInfo> tableFilters, List<String> tableProjections, Integer rowLimit) {
+ public List<KuduScanToken> scanTokens(
+ List<KuduFilterInfo> tableFilters, List<String> tableProjections, Integer rowLimit) {
KuduScanToken.KuduScanTokenBuilder tokenBuilder = client.newScanTokenBuilder(table);
if (tableProjections != null) {
@@ -117,7 +142,8 @@ public class KuduReader<T> implements AutoCloseable {
public KuduInputSplit[] createInputSplits(int minNumSplits) throws IOException {
- List<KuduScanToken> tokens = scanTokens(tableFilters, tableProjections, readerConfig.getRowLimit());
+ List<KuduScanToken> tokens =
+ scanTokens(tableFilters, tableProjections, readerConfig.getRowLimit());
KuduInputSplit[] splits = new KuduInputSplit[tokens.size()];
@@ -130,33 +156,24 @@ public class KuduReader<T> implements AutoCloseable {
locations.add(getLocation(replica.getRpcHost(), replica.getRpcPort()));
}
- KuduInputSplit split = new KuduInputSplit(
- token.serialize(),
- i,
- locations.toArray(new String[locations.size()])
- );
+ KuduInputSplit split =
+ new KuduInputSplit(
+ token.serialize(), i, locations.toArray(new String[locations.size()]));
splits[i] = split;
}
if (splits.length < minNumSplits) {
- log.warn(" The minimum desired number of splits with your configured parallelism level " +
- "is {}. Current kudu splits = {}. {} instances will remain idle.",
+ log.warn(
+ " The minimum desired number of splits with your configured parallelism level "
+ + "is {}. Current kudu splits = {}. {} instances will remain idle.",
minNumSplits,
splits.length,
- (minNumSplits - splits.length)
- );
+ (minNumSplits - splits.length));
}
return splits;
}
- /**
- * Returns a endpoint url in the following format: <host>:<ip>
- *
- * @param host Hostname
- * @param port Port
- * @return Formatted URL
- */
private String getLocation(String host, Integer port) {
return host + ":" + port;
}
@@ -179,4 +196,3 @@ public class KuduReader<T> implements AutoCloseable {
}
}
}
-
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderConfig.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderConfig.java
index 4727488..43068b5 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderConfig.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderConfig.java
@@ -14,17 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.reader;
-import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.flink.annotation.PublicEvolving;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
import java.io.Serializable;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
- * Configuration used by {@link org.apache.flink.connectors.kudu.format.KuduRowInputFormat}. Specifies connection and other necessary properties.
+ * Configuration used by {@link org.apache.flink.connectors.kudu.format.KuduRowInputFormat}.
+ * Specifies connection and other necessary properties.
*/
@PublicEvolving
public class KuduReaderConfig implements Serializable {
@@ -32,9 +35,7 @@ public class KuduReaderConfig implements Serializable {
private final String masters;
private final int rowLimit;
- private KuduReaderConfig(
- String masters,
- int rowLimit) {
+ private KuduReaderConfig(String masters, int rowLimit) {
this.masters = checkNotNull(masters, "Kudu masters cannot be null");
this.rowLimit = checkNotNull(rowLimit, "Kudu rowLimit cannot be null");
@@ -56,9 +57,7 @@ public class KuduReaderConfig implements Serializable {
.toString();
}
- /**
- * Builder for the {@link KuduReaderConfig}.
- */
+ /** Builder for the {@link KuduReaderConfig}. */
public static class Builder {
private static final int DEFAULT_ROW_LIMIT = 0;
@@ -83,9 +82,7 @@ public class KuduReaderConfig implements Serializable {
}
public KuduReaderConfig build() {
- return new KuduReaderConfig(
- masters,
- rowLimit);
+ return new KuduReaderConfig(masters, rowLimit);
}
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderIterator.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderIterator.java
index 543e41e..805f258 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderIterator.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/reader/KuduReaderIterator.java
@@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.reader;
import org.apache.flink.annotation.Internal;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
+
import org.apache.kudu.client.KuduException;
import org.apache.kudu.client.KuduScanner;
import org.apache.kudu.client.RowResult;
@@ -25,16 +27,18 @@ import org.apache.kudu.client.RowResultIterator;
import java.io.Serializable;
+/** An iterator that helps to iterate on Kudu record rows. */
@Internal
public class KuduReaderIterator<T> implements Serializable {
private final KuduScanner scanner;
- private final RowResultConvertor<T> rowResultConvertor;
+ private final RowResultConverter<T> rowResultConverter;
private RowResultIterator rowIterator;
- public KuduReaderIterator(KuduScanner scanner, RowResultConvertor<T> rowResultConvertor) throws KuduException {
+ public KuduReaderIterator(KuduScanner scanner, RowResultConverter<T> rowResultConverter)
+ throws KuduException {
this.scanner = scanner;
- this.rowResultConvertor = rowResultConvertor;
+ this.rowResultConverter = rowResultConverter;
nextRows();
}
@@ -55,7 +59,7 @@ public class KuduReaderIterator<T> implements Serializable {
public T next() {
RowResult row = this.rowIterator.next();
- return rowResultConvertor.convertor(row);
+ return rowResultConverter.convert(row);
}
private void nextRows() throws KuduException {
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/AbstractSingleOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/AbstractSingleOperationMapper.java
index 794d56b..cb6062a 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/AbstractSingleOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/AbstractSingleOperationMapper.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.Operation;
import org.apache.kudu.client.PartialRow;
@@ -26,14 +28,13 @@ import java.util.List;
import java.util.Optional;
/**
- * Base implementation for {@link KuduOperationMapper}s that have one-to-one input to
- * Kudu operation mapping. It requires a fixed table schema to be provided at construction
- * time and only requires users to implement a getter for a specific column index (relative
- * to the ones provided in the constructor).
- * <br>
- * Supports both fixed operation type per record by specifying the {@link KuduOperation} or a
- * custom implementation for creating the base {@link Operation} throwugh the
- * {@link #createBaseOperation(Object, KuduTable)} method.
+ * Base implementation for {@link KuduOperationMapper}s that have one-to-one input to Kudu operation
+ * mapping. It requires a fixed table schema to be provided at construction time and only requires
+ * users to implement a getter for a specific column index (relative to the ones provided in the
+ * constructor). <br>
+ * Supports both fixed operation type per record by specifying the {@link KuduOperation} or a custom
+ * implementation for creating the base {@link Operation} through the {@link
+ * #createBaseOperation(Object, KuduTable)} method.
*
* @param <T> Input type
*/
@@ -56,14 +57,15 @@ public abstract class AbstractSingleOperationMapper<T> implements KuduOperationM
* Returns the object corresponding to the given column index.
*
* @param input Input element
- * @param i Column index
+ * @param i Column index
* @return Column value
*/
public abstract Object getField(T input, int i);
public Optional<Operation> createBaseOperation(T input, KuduTable table) {
if (operation == null) {
- throw new UnsupportedOperationException("createBaseOperation must be overridden if no operation specified in constructor");
+ throw new UnsupportedOperationException(
+ "createBaseOperation must be overridden if no operation specified in constructor");
}
switch (operation) {
case INSERT:
@@ -96,6 +98,7 @@ public abstract class AbstractSingleOperationMapper<T> implements KuduOperationM
return Collections.singletonList(operation);
}
+ /** Kudu operation types. */
public enum KuduOperation {
INSERT,
UPDATE,
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduOperationMapper.java
index 886a3ea..310d3fc 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduOperationMapper.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.PublicEvolving;
+
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.Operation;
@@ -24,9 +26,9 @@ import java.io.Serializable;
import java.util.List;
/**
- * Encapsulates the logic of mapping input records (of a DataStream) to operations
- * executed in Kudu. By allowing to return a list of operations we give flexibility
- * to the implementers to provide more sophisticated logic.
+ * Encapsulates the logic of mapping input records (of a DataStream) to operations executed in Kudu.
+ * By allowing to return a list of operations we give flexibility to the implementers to provide
+ * more sophisticated logic.
*
* @param <T> Type of the input data
*/
@@ -34,13 +36,11 @@ import java.util.List;
public interface KuduOperationMapper<T> extends Serializable {
/**
- * Create a list of operations to be executed by the {@link KuduWriter} for the
- * current input
+ * Create a list of operations to be executed by the {@link KuduWriter} for the current input.
*
* @param input input element
* @param table table for which the operations should be created
* @return List of operations to be executed on the table
*/
List<Operation> createOperations(T input, KuduTable table);
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriter.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriter.java
index 2171a43..246739c 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriter.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriter.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.Internal;
@@ -21,7 +22,14 @@ import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
import org.apache.flink.connectors.kudu.connector.failure.DefaultKuduFailureHandler;
import org.apache.flink.connectors.kudu.connector.failure.KuduFailureHandler;
-import org.apache.kudu.client.*;
+
+import org.apache.kudu.client.DeleteTableResponse;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduSession;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.client.Operation;
+import org.apache.kudu.client.OperationResponse;
+import org.apache.kudu.client.RowError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,6 +37,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
+/** Writer to write data to a Kudu table. */
@Internal
public class KuduWriter<T> implements AutoCloseable {
@@ -43,11 +52,20 @@ public class KuduWriter<T> implements AutoCloseable {
private transient KuduSession session;
private transient KuduTable table;
- public KuduWriter(KuduTableInfo tableInfo, KuduWriterConfig writerConfig, KuduOperationMapper<T> operationMapper) throws IOException {
+ public KuduWriter(
+ KuduTableInfo tableInfo,
+ KuduWriterConfig writerConfig,
+ KuduOperationMapper<T> operationMapper)
+ throws IOException {
this(tableInfo, writerConfig, operationMapper, new DefaultKuduFailureHandler());
}
- public KuduWriter(KuduTableInfo tableInfo, KuduWriterConfig writerConfig, KuduOperationMapper<T> operationMapper, KuduFailureHandler failureHandler) throws IOException {
+ public KuduWriter(
+ KuduTableInfo tableInfo,
+ KuduWriterConfig writerConfig,
+ KuduOperationMapper<T> operationMapper,
+ KuduFailureHandler failureHandler)
+ throws IOException {
this.tableInfo = tableInfo;
this.writerConfig = writerConfig;
this.failureHandler = failureHandler;
@@ -79,7 +97,8 @@ public class KuduWriter<T> implements AutoCloseable {
return client.openTable(tableName);
}
if (tableInfo.getCreateTableIfNotExists()) {
- return client.createTable(tableName, tableInfo.getSchema(), tableInfo.getCreateTableOptions());
+ return client.createTable(
+ tableName, tableInfo.getSchema(), tableInfo.getCreateTableOptions());
}
throw new RuntimeException("Table " + tableName + " does not exist.");
}
@@ -139,7 +158,9 @@ public class KuduWriter<T> implements AutoCloseable {
}
private void checkAsyncErrors() throws IOException {
- if (session.countPendingErrors() == 0) { return; }
+ if (session.countPendingErrors() == 0) {
+ return;
+ }
List<RowError> errors = Arrays.asList(session.getPendingErrors().getRowErrors());
failureHandler.onFailure(errors);
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriterConfig.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriterConfig.java
index 9b63494..0bf0e88 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriterConfig.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/KuduWriterConfig.java
@@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
-import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.flink.annotation.PublicEvolving;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.kudu.client.AsyncKuduClient;
import java.io.Serializable;
@@ -27,8 +29,9 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
import static org.apache.kudu.client.SessionConfiguration.FlushMode;
/**
- * Configuration used by {@link org.apache.flink.connectors.kudu.streaming.KuduSink} and {@link org.apache.flink.connectors.kudu.format.KuduOutputFormat}.
- * Specifies connection and other necessary properties.
+ * Configuration used by {@link org.apache.flink.connectors.kudu.streaming.KuduSink} and {@link
+ * org.apache.flink.connectors.kudu.format.KuduOutputFormat}. Specifies connection and other
+ * necessary properties.
*/
@PublicEvolving
public class KuduWriterConfig implements Serializable {
@@ -95,9 +98,7 @@ public class KuduWriterConfig implements Serializable {
.toString();
}
- /**
- * Builder for the {@link KuduWriterConfig}.
- */
+ /** Builder for the {@link KuduWriterConfig}. */
public static class Builder {
private String masters;
private FlushMode flushMode = FlushMode.AUTO_FLUSH_BACKGROUND;
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/PojoOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/PojoOperationMapper.java
index 253146c..fbff653 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/PojoOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/PojoOperationMapper.java
@@ -14,20 +14,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.PublicEvolving;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+/** Logic to map a given POJO to a Kudu-compatible format. */
@PublicEvolving
public class PojoOperationMapper<T> extends AbstractSingleOperationMapper<T> {
private final Field[] fields;
- protected PojoOperationMapper(Class<T> pojoClass, String[] columnNames) { this(pojoClass, columnNames, null); }
-
public PojoOperationMapper(Class<T> pojoClass, String[] columnNames, KuduOperation operation) {
super(columnNames, operation);
fields = initFields(pojoClass, columnNames);
@@ -45,18 +49,24 @@ public class PojoOperationMapper<T> extends AbstractSingleOperationMapper<T> {
private Field[] initFields(Class<T> pojoClass, String[] columnNames) {
Map<String, Field> allFields = new HashMap<>();
- getAllFields(new ArrayList<>(), pojoClass).stream().forEach(f -> {
- if (!allFields.containsKey(f.getName())) {
- allFields.put(f.getName(), f);
- }
- });
+ getAllFields(new ArrayList<>(), pojoClass)
+ .forEach(
+ f -> {
+ if (!allFields.containsKey(f.getName())) {
+ allFields.put(f.getName(), f);
+ }
+ });
Field[] fields = new Field[columnNames.length];
for (int i = 0; i < columnNames.length; i++) {
Field f = allFields.get(columnNames[i]);
if (f == null) {
- throw new RuntimeException("Cannot find field " + columnNames[i] + ". List of detected fields: " + allFields.keySet());
+ throw new RuntimeException(
+ "Cannot find field "
+ + columnNames[i]
+ + ". List of detected fields: "
+ + allFields.keySet());
}
f.setAccessible(true);
fields[i] = f;
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowDataUpsertOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowDataUpsertOperationMapper.java
index d4f0182..85b9a13 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowDataUpsertOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowDataUpsertOperationMapper.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.Internal;
@@ -24,6 +25,7 @@ import org.apache.flink.table.data.StringData;
import org.apache.flink.table.types.DataType;
import org.apache.flink.table.types.logical.DecimalType;
import org.apache.flink.table.types.logical.LogicalType;
+
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.Operation;
import org.slf4j.Logger;
@@ -34,12 +36,12 @@ import java.util.Optional;
import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getPrecision;
+/** Logic to map Flink UPSERT RowData to a Kudu-compatible format. */
@Internal
public class RowDataUpsertOperationMapper extends AbstractSingleOperationMapper<RowData> {
private static final Logger LOG = LoggerFactory.getLogger(RowDataUpsertOperationMapper.class);
-
private static final int MIN_TIME_PRECISION = 0;
private static final int MAX_TIME_PRECISION = 3;
private static final int MIN_TIMESTAMP_PRECISION = 0;
@@ -49,9 +51,10 @@ public class RowDataUpsertOperationMapper extends AbstractSingleOperationMapper<
public RowDataUpsertOperationMapper(TableSchema schema) {
super(schema.getFieldNames());
- logicalTypes = Arrays.stream(schema.getFieldDataTypes())
- .map(DataType::getLogicalType)
- .toArray(LogicalType[]::new);
+ logicalTypes =
+ Arrays.stream(schema.getFieldDataTypes())
+ .map(DataType::getLogicalType)
+ .toArray(LogicalType[]::new);
}
@Override
@@ -66,29 +69,31 @@ public class RowDataUpsertOperationMapper extends AbstractSingleOperationMapper<
LogicalType fieldType = logicalTypes[i];
switch (fieldType.getTypeRoot()) {
case CHAR:
- case VARCHAR: {
- StringData data = input.getString(i);
- if (data != null) {
- return data.toString();
+ case VARCHAR:
+ {
+ StringData data = input.getString(i);
+ if (data != null) {
+ return data.toString();
+ }
+ return null;
}
- return null;
- }
case BOOLEAN:
return input.getBoolean(i);
case BINARY:
case VARBINARY:
return input.getBinary(i);
- case DECIMAL: {
- DecimalType decimalType = (DecimalType) fieldType;
- final int precision = decimalType.getPrecision();
- final int scale = decimalType.getScale();
- DecimalData data = input.getDecimal(i, precision, scale);
- if (data != null) {
- return data.toBigDecimal();
- } else {
- return null;
+ case DECIMAL:
+ {
+ DecimalType decimalType = (DecimalType) fieldType;
+ final int precision = decimalType.getPrecision();
+ final int scale = decimalType.getScale();
+ DecimalData data = input.getDecimal(i, precision, scale);
+ if (data != null) {
+ return data.toBigDecimal();
+ } else {
+ return null;
+ }
}
- }
case TINYINT:
return input.getByte(i);
case SMALLINT:
@@ -101,8 +106,10 @@ public class RowDataUpsertOperationMapper extends AbstractSingleOperationMapper<
final int timePrecision = getPrecision(fieldType);
if (timePrecision < MIN_TIME_PRECISION || timePrecision > MAX_TIME_PRECISION) {
throw new UnsupportedOperationException(
- String.format("The precision %s of TIME type is out of the range [%s, %s] supported by " +
- "kudu connector", timePrecision, MIN_TIME_PRECISION, MAX_TIME_PRECISION));
+ String.format(
+ "The precision %s of TIME type is out of the range [%s, %s] supported by "
+ + "kudu connector",
+ timePrecision, MIN_TIME_PRECISION, MAX_TIME_PRECISION));
}
return input.getInt(i);
case BIGINT:
@@ -115,10 +122,14 @@ public class RowDataUpsertOperationMapper extends AbstractSingleOperationMapper<
case TIMESTAMP_WITHOUT_TIME_ZONE:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
final int timestampPrecision = getPrecision(fieldType);
- if (timestampPrecision < MIN_TIMESTAMP_PRECISION || timestampPrecision > MAX_TIMESTAMP_PRECISION) {
+ if (timestampPrecision < MIN_TIMESTAMP_PRECISION
+ || timestampPrecision > MAX_TIMESTAMP_PRECISION) {
throw new UnsupportedOperationException(
- String.format("The precision %s of TIMESTAMP type is out of the range [%s, %s] supported " +
- "by kudu connector", timestampPrecision, MIN_TIMESTAMP_PRECISION,
+ String.format(
+ "The precision %s of TIMESTAMP type is out of the range [%s, %s] supported "
+ + "by kudu connector",
+ timestampPrecision,
+ MIN_TIMESTAMP_PRECISION,
MAX_TIMESTAMP_PRECISION));
}
return input.getTimestamp(i, timestampPrecision).toTimestamp();
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowOperationMapper.java
index 2e90598..0351814 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/RowOperationMapper.java
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.types.Row;
+/** Logic to map Flink Row to a "Kudu upsert"-compatible format. */
@PublicEvolving
public class RowOperationMapper extends AbstractSingleOperationMapper<Row> {
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/TupleOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/TupleOperationMapper.java
index 491168b..6da4aa4 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/TupleOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/connector/writer/TupleOperationMapper.java
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector.writer;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.java.tuple.Tuple;
+/** Logic to map a Flink Tuple to a Kudu-compatible format. */
@PublicEvolving
public class TupleOperationMapper<T extends Tuple> extends AbstractSingleOperationMapper<T> {
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/AbstractKuduInputFormat.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/AbstractKuduInputFormat.java
index 4976241..825da03 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/AbstractKuduInputFormat.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/AbstractKuduInputFormat.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.annotation.PublicEvolving;
@@ -24,13 +25,14 @@ import org.apache.flink.api.java.typeutils.ResultTypeQueryable;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduInputSplit;
import org.apache.flink.connectors.kudu.connector.reader.KuduReader;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderIterator;
import org.apache.flink.connectors.kudu.table.KuduCatalog;
import org.apache.flink.core.io.InputSplitAssigner;
+
import org.apache.kudu.client.KuduException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,15 +44,16 @@ import java.util.List;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
- * Input format for reading the contents of a Kudu table (defined by the provided {@link KuduTableInfo}) in both batch
- * and stream programs. Rows of the Kudu table are mapped to {@link T} instances that can converted to other data
- * types by the user later if necessary.
+ * Input format for reading the contents of a Kudu table (defined by the provided {@link
+ * KuduTableInfo}) in both batch and stream programs. Rows of the Kudu table are mapped to {@link T}
+ * instances that can converted to other data types by the user later if necessary.
*
- * <p> For programmatic access to the schema of the input rows users can use the {@link KuduCatalog}
+ * <p>For programmatic access to the schema of the input rows users can use the {@link KuduCatalog}
* or overwrite the column order manually by providing a list of projected column names.
*/
@PublicEvolving
-public abstract class AbstractKuduInputFormat<T> extends RichInputFormat<T, KuduInputSplit> implements ResultTypeQueryable<T> {
+public abstract class AbstractKuduInputFormat<T> extends RichInputFormat<T, KuduInputSplit>
+ implements ResultTypeQueryable<T> {
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -58,27 +61,36 @@ public abstract class AbstractKuduInputFormat<T> extends RichInputFormat<T, Kudu
private final KuduTableInfo tableInfo;
private final List<KuduFilterInfo> tableFilters;
private final List<String> tableProjections;
- private final RowResultConvertor<T> rowResultConvertor;
+ private final RowResultConverter<T> rowResultConverter;
private boolean endReached;
private transient KuduReader<T> kuduReader;
private transient KuduReaderIterator<T> resultIterator;
- public AbstractKuduInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor,
- KuduTableInfo tableInfo) {
- this(readerConfig, rowResultConvertor, tableInfo, new ArrayList<>(), null);
+ public AbstractKuduInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter,
+ KuduTableInfo tableInfo) {
+ this(readerConfig, rowResultConverter, tableInfo, new ArrayList<>(), null);
}
- public AbstractKuduInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor,
- KuduTableInfo tableInfo, List<String> tableProjections) {
- this(readerConfig, rowResultConvertor, tableInfo, new ArrayList<>(), tableProjections);
+ public AbstractKuduInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<String> tableProjections) {
+ this(readerConfig, rowResultConverter, tableInfo, new ArrayList<>(), tableProjections);
}
- public AbstractKuduInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<T> rowResultConvertor,
- KuduTableInfo tableInfo, List<KuduFilterInfo> tableFilters,
- List<String> tableProjections) {
+ public AbstractKuduInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<T> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<KuduFilterInfo> tableFilters,
+ List<String> tableProjections) {
this.readerConfig = checkNotNull(readerConfig, "readerConfig could not be null");
- this.rowResultConvertor = checkNotNull(rowResultConvertor, "rowResultConvertor could not be null");
+ this.rowResultConverter =
+ checkNotNull(rowResultConverter, "rowResultConvertor could not be null");
this.tableInfo = checkNotNull(tableInfo, "tableInfo could not be null");
this.tableFilters = checkNotNull(tableFilters, "tableFilters could not be null");
this.tableProjections = tableProjections;
@@ -87,8 +99,7 @@ public abstract class AbstractKuduInputFormat<T> extends RichInputFormat<T, Kudu
}
@Override
- public void configure(Configuration parameters) {
- }
+ public void configure(Configuration parameters) {}
@Override
public void open(KuduInputSplit split) throws IOException {
@@ -100,7 +111,13 @@ public abstract class AbstractKuduInputFormat<T> extends RichInputFormat<T, Kudu
private void startKuduReader() throws IOException {
if (kuduReader == null) {
- kuduReader = new KuduReader<>(tableInfo, readerConfig, rowResultConvertor, tableFilters, tableProjections);
+ kuduReader =
+ new KuduReader<>(
+ tableInfo,
+ readerConfig,
+ rowResultConverter,
+ tableFilters,
+ tableProjections);
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduOutputFormat.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduOutputFormat.java
index bc1b031..7a2227c 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduOutputFormat.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduOutputFormat.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.annotation.PublicEvolving;
@@ -28,6 +29,7 @@ import org.apache.flink.connectors.kudu.connector.writer.KuduWriterConfig;
import org.apache.flink.runtime.state.FunctionInitializationContext;
import org.apache.flink.runtime.state.FunctionSnapshotContext;
import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,8 +38,8 @@ import java.io.IOException;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
- * Output format for writing data into a Kudu table (defined by the provided {@link KuduTableInfo}) in both batch
- * and stream programs.
+ * Output format for writing data into a Kudu table (defined by the provided {@link KuduTableInfo})
+ * in both batch and stream programs.
*/
@PublicEvolving
public class KuduOutputFormat<IN> extends RichOutputFormat<IN> implements CheckpointedFunction {
@@ -51,11 +53,18 @@ public class KuduOutputFormat<IN> extends RichOutputFormat<IN> implements Checkp
private transient KuduWriter kuduWriter;
- public KuduOutputFormat(KuduWriterConfig writerConfig, KuduTableInfo tableInfo, KuduOperationMapper<IN> opsMapper) {
+ public KuduOutputFormat(
+ KuduWriterConfig writerConfig,
+ KuduTableInfo tableInfo,
+ KuduOperationMapper<IN> opsMapper) {
this(writerConfig, tableInfo, opsMapper, new DefaultKuduFailureHandler());
}
- public KuduOutputFormat(KuduWriterConfig writerConfig, KuduTableInfo tableInfo, KuduOperationMapper<IN> opsMapper, KuduFailureHandler failureHandler) {
+ public KuduOutputFormat(
+ KuduWriterConfig writerConfig,
+ KuduTableInfo tableInfo,
+ KuduOperationMapper<IN> opsMapper,
+ KuduFailureHandler failureHandler) {
this.tableInfo = checkNotNull(tableInfo, "tableInfo could not be null");
this.writerConfig = checkNotNull(writerConfig, "config could not be null");
this.opsMapper = checkNotNull(opsMapper, "opsMapper could not be null");
@@ -63,8 +72,7 @@ public class KuduOutputFormat<IN> extends RichOutputFormat<IN> implements Checkp
}
@Override
- public void configure(Configuration parameters) {
- }
+ public void configure(Configuration parameters) {}
@Override
public void open(int taskNumber, int numTasks) throws IOException {
@@ -89,7 +97,6 @@ public class KuduOutputFormat<IN> extends RichOutputFormat<IN> implements Checkp
}
@Override
- public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception {
-
- }
+ public void initializeState(FunctionInitializationContext functionInitializationContext)
+ throws Exception {}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormat.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormat.java
index bb75f61..0cf07c3 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormat.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormat.java
@@ -21,28 +21,38 @@ import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.table.data.RowData;
import java.util.List;
-/**
- * InputFormat based on the rowData object type
- */
+/** InputFormat based on the rowData object type. */
@PublicEvolving
public class KuduRowDataInputFormat extends AbstractKuduInputFormat<RowData> {
- public KuduRowDataInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<RowData> rowResultConvertor, KuduTableInfo tableInfo) {
- super(readerConfig, rowResultConvertor, tableInfo);
+ public KuduRowDataInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<RowData> rowResultConverter,
+ KuduTableInfo tableInfo) {
+ super(readerConfig, rowResultConverter, tableInfo);
}
- public KuduRowDataInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<RowData> rowResultConvertor, KuduTableInfo tableInfo, List<String> tableProjections) {
- super(readerConfig, rowResultConvertor, tableInfo, tableProjections);
+ public KuduRowDataInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<RowData> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<String> tableProjections) {
+ super(readerConfig, rowResultConverter, tableInfo, tableProjections);
}
- public KuduRowDataInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<RowData> rowResultConvertor, KuduTableInfo tableInfo, List<KuduFilterInfo> tableFilters, List<String> tableProjections) {
- super(readerConfig, rowResultConvertor, tableInfo, tableFilters, tableProjections);
+ public KuduRowDataInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<RowData> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<KuduFilterInfo> tableFilters,
+ List<String> tableProjections) {
+ super(readerConfig, rowResultConverter, tableInfo, tableFilters, tableProjections);
}
@Override
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormat.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormat.java
index 935de8f..c220be3 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormat.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormat.java
@@ -14,38 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.types.Row;
import java.util.List;
-/**
- * InputFormat based on the row object type
- */
+/** InputFormat based on the row object type. */
@PublicEvolving
public class KuduRowInputFormat extends AbstractKuduInputFormat<Row> {
- public KuduRowInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<Row> rowResultConvertor,
- KuduTableInfo tableInfo) {
- super(readerConfig, rowResultConvertor, tableInfo);
+ public KuduRowInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<Row> rowResultConverter,
+ KuduTableInfo tableInfo) {
+ super(readerConfig, rowResultConverter, tableInfo);
}
- public KuduRowInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<Row> rowResultConvertor,
- KuduTableInfo tableInfo, List<String> tableProjections) {
- super(readerConfig, rowResultConvertor, tableInfo, tableProjections);
+ public KuduRowInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<Row> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<String> tableProjections) {
+ super(readerConfig, rowResultConverter, tableInfo, tableProjections);
}
- public KuduRowInputFormat(KuduReaderConfig readerConfig, RowResultConvertor<Row> rowResultConvertor,
- KuduTableInfo tableInfo, List<KuduFilterInfo> tableFilters,
- List<String> tableProjections) {
- super(readerConfig, rowResultConvertor, tableInfo, tableFilters, tableProjections);
+ public KuduRowInputFormat(
+ KuduReaderConfig readerConfig,
+ RowResultConverter<Row> rowResultConverter,
+ KuduTableInfo tableInfo,
+ List<KuduFilterInfo> tableFilters,
+ List<String> tableProjections) {
+ super(readerConfig, rowResultConverter, tableInfo, tableFilters, tableProjections);
}
@Override
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/streaming/KuduSink.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/streaming/KuduSink.java
index a2e3e47..7374f3a 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/streaming/KuduSink.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/streaming/KuduSink.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.streaming;
import org.apache.flink.annotation.PublicEvolving;
@@ -28,18 +29,20 @@ import org.apache.flink.runtime.state.FunctionInitializationContext;
import org.apache.flink.runtime.state.FunctionSnapshotContext;
import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
- * Streaming Sink that executes Kudu operations based on the incoming elements.
- * The target Kudu table is defined in the {@link KuduTableInfo} object together with parameters for table
- * creation in case the table does not exist.
- * <p>
- * Incoming records are mapped to Kudu table operations using the provided {@link KuduOperationMapper} logic. While
- * failures resulting from the operations are handled by the {@link KuduFailureHandler} instance.
+ * Streaming Sink that executes Kudu operations based on the incoming elements. The target Kudu
+ * table is defined in the {@link KuduTableInfo} object together with parameters for table creation
+ * in case the table does not exist.
+ *
+ * <p>Incoming records are mapped to Kudu table operations using the provided {@link
+ * KuduOperationMapper} logic. While failures resulting from the operations are handled by the
+ * {@link KuduFailureHandler} instance.
*
* @param <IN> Type of the input records
*/
@@ -55,27 +58,34 @@ public class KuduSink<IN> extends RichSinkFunction<IN> implements CheckpointedFu
private transient KuduWriter kuduWriter;
/**
- * Creates a new {@link KuduSink} that will execute operations against the specified Kudu table (defined in {@link KuduTableInfo})
- * for the incoming stream elements.
+ * Creates a new {@link KuduSink} that will execute operations against the specified Kudu table
+ * (defined in {@link KuduTableInfo}) for the incoming stream elements.
*
* @param writerConfig Writer configuration
- * @param tableInfo Table information for the target table
- * @param opsMapper Mapping logic from inputs to Kudu operations
+ * @param tableInfo Table information for the target table
+ * @param opsMapper Mapping logic from inputs to Kudu operations
*/
- public KuduSink(KuduWriterConfig writerConfig, KuduTableInfo tableInfo, KuduOperationMapper<IN> opsMapper) {
+ public KuduSink(
+ KuduWriterConfig writerConfig,
+ KuduTableInfo tableInfo,
+ KuduOperationMapper<IN> opsMapper) {
this(writerConfig, tableInfo, opsMapper, new DefaultKuduFailureHandler());
}
/**
- * Creates a new {@link KuduSink} that will execute operations against the specified Kudu table (defined in {@link KuduTableInfo})
- * for the incoming stream elements.
+ * Creates a new {@link KuduSink} that will execute operations against the specified Kudu table
+ * (defined in {@link KuduTableInfo}) for the incoming stream elements.
*
- * @param writerConfig Writer configuration
- * @param tableInfo Table information for the target table
- * @param opsMapper Mapping logic from inputs to Kudu operations
+ * @param writerConfig Writer configuration
+ * @param tableInfo Table information for the target table
+ * @param opsMapper Mapping logic from inputs to Kudu operations
* @param failureHandler Custom failure handler instance
*/
- public KuduSink(KuduWriterConfig writerConfig, KuduTableInfo tableInfo, KuduOperationMapper<IN> opsMapper, KuduFailureHandler failureHandler) {
+ public KuduSink(
+ KuduWriterConfig writerConfig,
+ KuduTableInfo tableInfo,
+ KuduOperationMapper<IN> opsMapper,
+ KuduFailureHandler failureHandler) {
this.tableInfo = checkNotNull(tableInfo, "tableInfo could not be null");
this.writerConfig = checkNotNull(writerConfig, "config could not be null");
this.opsMapper = checkNotNull(opsMapper, "opsMapper could not be null");
@@ -109,7 +119,6 @@ public class KuduSink<IN> extends RichSinkFunction<IN> implements CheckpointedFu
}
@Override
- public void initializeState(FunctionInitializationContext functionInitializationContext) throws Exception {
- }
-
+ public void initializeState(FunctionInitializationContext functionInitializationContext)
+ throws Exception {}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/AbstractReadOnlyCatalog.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/AbstractReadOnlyCatalog.java
index ffe02a8..eb53e85 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/AbstractReadOnlyCatalog.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/AbstractReadOnlyCatalog.java
@@ -19,110 +19,171 @@
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.annotation.Internal;
-import org.apache.flink.table.catalog.*;
-import org.apache.flink.table.catalog.exceptions.*;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.exceptions.TablePartitionedException;
import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
-/**
- * Read-only catalog.
- */
+/** Read-only catalog. */
@Internal
public abstract class AbstractReadOnlyCatalog extends AbstractCatalog {
- private static final CatalogException UNSUPPORTED_ERR = new CatalogException("This action is not supported for read-only catalogs");
+ private static final CatalogException UNSUPPORTED_ERR =
+ new CatalogException("This action is not supported for read-only catalogs");
public AbstractReadOnlyCatalog(String name, String defaultDatabase) {
super(name, defaultDatabase);
}
@Override
- public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists) throws DatabaseAlreadyExistException, CatalogException {
+ public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+ throws DatabaseAlreadyExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade) throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+ public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+ throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists) throws DatabaseNotExistException, CatalogException {
+ public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
+ throws DatabaseNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException {
+ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+ throws TableAlreadyExistException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterTable(ObjectPath tablePath, CatalogBaseTable newTable, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void alterTable(
+ ObjectPath tablePath, CatalogBaseTable newTable, boolean ignoreIfNotExists)
+ throws TableNotExistException {
throw UNSUPPORTED_ERR;
}
@Override
- public CatalogPartition getPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws PartitionNotExistException, CatalogException {
+ public CatalogPartition getPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec)
+ throws PartitionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void createPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogPartition partition, boolean ignoreIfExists) throws TableNotExistException, TableNotPartitionedException, PartitionSpecInvalidException, PartitionAlreadyExistsException, CatalogException {
+ public void createPartition(
+ ObjectPath tablePath,
+ CatalogPartitionSpec partitionSpec,
+ CatalogPartition partition,
+ boolean ignoreIfExists)
+ throws TableNotExistException, TableNotPartitionedException,
+ PartitionSpecInvalidException, PartitionAlreadyExistsException,
+ CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void dropPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, boolean ignoreIfNotExists) throws PartitionNotExistException, CatalogException {
+ public void dropPartition(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec, boolean ignoreIfNotExists)
+ throws PartitionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogPartition newPartition, boolean ignoreIfNotExists) throws PartitionNotExistException, CatalogException {
+ public void alterPartition(
+ ObjectPath tablePath,
+ CatalogPartitionSpec partitionSpec,
+ CatalogPartition newPartition,
+ boolean ignoreIfNotExists)
+ throws PartitionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
+ public void createFunction(
+ ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
+ throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterFunction(ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
+ public void alterFunction(
+ ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
+ throws FunctionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists) throws FunctionNotExistException, CatalogException {
+ public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
+ throws FunctionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterTableStatistics(ObjectPath tablePath, CatalogTableStatistics tableStatistics, boolean ignoreIfNotExists) throws TableNotExistException, CatalogException {
+ public void alterTableStatistics(
+ ObjectPath tablePath, CatalogTableStatistics tableStatistics, boolean ignoreIfNotExists)
+ throws TableNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterTableColumnStatistics(ObjectPath tablePath, CatalogColumnStatistics columnStatistics, boolean ignoreIfNotExists) throws TableNotExistException, CatalogException, TablePartitionedException {
+ public void alterTableColumnStatistics(
+ ObjectPath tablePath,
+ CatalogColumnStatistics columnStatistics,
+ boolean ignoreIfNotExists)
+ throws TableNotExistException, CatalogException, TablePartitionedException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterPartitionStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogTableStatistics partitionStatistics, boolean ignoreIfNotExists) throws PartitionNotExistException, CatalogException {
+ public void alterPartitionStatistics(
+ ObjectPath tablePath,
+ CatalogPartitionSpec partitionSpec,
+ CatalogTableStatistics partitionStatistics,
+ boolean ignoreIfNotExists)
+ throws PartitionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void alterPartitionColumnStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogColumnStatistics columnStatistics, boolean ignoreIfNotExists) throws PartitionNotExistException, CatalogException {
+ public void alterPartitionColumnStatistics(
+ ObjectPath tablePath,
+ CatalogPartitionSpec partitionSpec,
+ CatalogColumnStatistics columnStatistics,
+ boolean ignoreIfNotExists)
+ throws PartitionNotExistException, CatalogException {
throw UNSUPPORTED_ERR;
}
@Override
- public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+ throws TableNotExistException {
throw UNSUPPORTED_ERR;
}
@Override
- public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+ throws TableNotExistException {
throw UNSUPPORTED_ERR;
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduCatalog.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduCatalog.java
index 50e45b1..bd33250 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduCatalog.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduCatalog.java
@@ -22,13 +22,25 @@ import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
import org.apache.flink.connectors.kudu.table.utils.KuduTableUtils;
import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.*;
-import org.apache.flink.table.catalog.exceptions.*;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
import org.apache.flink.table.expressions.Expression;
import org.apache.flink.table.factories.TableFactory;
import org.apache.flink.util.StringUtils;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.client.AlterTableOptions;
import org.apache.kudu.client.KuduClient;
@@ -38,19 +50,30 @@ import org.apache.kudu.shaded.com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
-import static org.apache.flink.connectors.kudu.table.KuduTableFactory.*;
+import static org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_HASH_COLS;
+import static org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_PRIMARY_KEY_COLS;
+import static org.apache.flink.connectors.kudu.table.KuduTableFactory.KUDU_REPLICAS;
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* Catalog for reading and creating Kudu tables.
- * @deprecated After this class based on {@link KuduTableFactory},
- * but flink upgrade {@link org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory}
- * {@link KuduCatalog} underlying the use of TableFactory also needs to
- * update,So this class is replaced by the {@link org.apache.flink.connectors.kudu.table.dynamic.catalog.KuduDynamicCatalog} class
+ *
+ * @deprecated After this class based on {@link KuduTableFactory}, but flink upgrade {@link
+ * org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory} {@link
+ * KuduCatalog} underlying the use of TableFactory also needs to update,So this class is
+ * replaced by the {@link
+ * org.apache.flink.connectors.kudu.table.dynamic.catalog.KuduDynamicCatalog} class
*/
@PublicEvolving
@Deprecated
@@ -113,8 +136,11 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public List<String> listTables(String databaseName) throws DatabaseNotExistException, CatalogException {
- checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");
+ public List<String> listTables(String databaseName)
+ throws DatabaseNotExistException, CatalogException {
+ checkArgument(
+ !StringUtils.isNullOrWhitespaceOnly(databaseName),
+ "databaseName cannot be null or empty");
if (!databaseExists(databaseName)) {
throw new DatabaseNotExistException(getName(), databaseName);
@@ -150,10 +176,12 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
try {
KuduTable kuduTable = kuduClient.openTable(tableName);
- CatalogTableImpl table = new CatalogTableImpl(
- KuduTableUtils.kuduToFlinkSchema(kuduTable.getSchema()),
- createTableProperties(tableName, kuduTable.getSchema().getPrimaryKeyColumns()),
- tableName);
+ CatalogTableImpl table =
+ new CatalogTableImpl(
+ KuduTableUtils.kuduToFlinkSchema(kuduTable.getSchema()),
+ createTableProperties(
+ tableName, kuduTable.getSchema().getPrimaryKeyColumns()),
+ tableName);
return table;
} catch (KuduException e) {
@@ -161,17 +189,22 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
}
- protected Map<String, String> createTableProperties(String tableName, List<ColumnSchema> primaryKeyColumns) {
+ protected Map<String, String> createTableProperties(
+ String tableName, List<ColumnSchema> primaryKeyColumns) {
Map<String, String> props = new HashMap<>();
props.put(KuduTableFactory.KUDU_MASTERS, kuduMasters);
- String primaryKeyNames = primaryKeyColumns.stream().map(ColumnSchema::getName).collect(Collectors.joining(","));
+ String primaryKeyNames =
+ primaryKeyColumns.stream()
+ .map(ColumnSchema::getName)
+ .collect(Collectors.joining(","));
props.put(KuduTableFactory.KUDU_PRIMARY_KEY_COLS, primaryKeyNames);
props.put(KuduTableFactory.KUDU_TABLE, tableName);
return props;
}
@Override
- public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+ throws TableNotExistException {
String tableName = tablePath.getObjectName();
try {
if (tableExists(tablePath)) {
@@ -185,7 +218,8 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+ throws TableNotExistException {
String tableName = tablePath.getObjectName();
try {
if (tableExists(tablePath)) {
@@ -198,7 +232,8 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
}
- public void createTable(KuduTableInfo tableInfo, boolean ignoreIfExists) throws CatalogException, TableAlreadyExistException {
+ public void createTable(KuduTableInfo tableInfo, boolean ignoreIfExists)
+ throws CatalogException, TableAlreadyExistException {
ObjectPath path = getObjectPath(tableInfo.getName());
if (tableExists(path)) {
if (ignoreIfExists) {
@@ -209,15 +244,16 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
try {
- kuduClient.createTable(tableInfo.getName(), tableInfo.getSchema(), tableInfo.getCreateTableOptions());
- } catch (
- KuduException e) {
+ kuduClient.createTable(
+ tableInfo.getName(), tableInfo.getSchema(), tableInfo.getCreateTableOptions());
+ } catch (KuduException e) {
throw new CatalogException("Could not create table " + tableInfo.getName(), e);
}
}
@Override
- public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException {
+ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+ throws TableAlreadyExistException {
Map<String, String> tableProperties = table.getOptions();
TableSchema tableSchema = table.getSchema();
@@ -229,19 +265,22 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
if (!tableProperties.keySet().containsAll(requiredProperties)) {
- throw new CatalogException("Missing required property. The following properties must be provided: " +
- requiredProperties.toString());
+ throw new CatalogException(
+ "Missing required property. The following properties must be provided: "
+ + requiredProperties.toString());
}
Set<String> permittedProperties = Sets.union(requiredProperties, optionalProperties);
if (!permittedProperties.containsAll(tableProperties.keySet())) {
- throw new CatalogException("Unpermitted properties were given. The following properties are allowed:" +
- permittedProperties.toString());
+ throw new CatalogException(
+ "Unpermitted properties were given. The following properties are allowed:"
+ + permittedProperties.toString());
}
String tableName = tablePath.getObjectName();
- KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, tableSchema, tableProperties);
+ KuduTableInfo tableInfo =
+ KuduTableUtils.createTableInfo(tableName, tableSchema, tableProperties);
createTable(tableInfo, ignoreIfExists);
}
@@ -252,17 +291,20 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath) throws CatalogException {
+ public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath)
+ throws CatalogException {
return CatalogColumnStatistics.UNKNOWN;
}
@Override
- public CatalogTableStatistics getPartitionStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public CatalogTableStatistics getPartitionStatistics(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return CatalogTableStatistics.UNKNOWN;
}
@Override
- public CatalogColumnStatistics getPartitionColumnStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public CatalogColumnStatistics getPartitionColumnStatistics(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return CatalogColumnStatistics.UNKNOWN;
}
@@ -272,7 +314,8 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
+ public CatalogDatabase getDatabase(String databaseName)
+ throws DatabaseNotExistException, CatalogException {
if (databaseName.equals(getDefaultDatabase())) {
return new CatalogDatabaseImpl(new HashMap<>(), null);
} else {
@@ -296,17 +339,20 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public List<CatalogPartitionSpec> listPartitions(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return Collections.emptyList();
}
@Override
- public List<CatalogPartitionSpec> listPartitionsByFilter(ObjectPath tablePath, List<Expression> filters) throws CatalogException {
+ public List<CatalogPartitionSpec> listPartitionsByFilter(
+ ObjectPath tablePath, List<Expression> filters) throws CatalogException {
return Collections.emptyList();
}
@Override
- public boolean partitionExists(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public boolean partitionExists(ObjectPath tablePath, CatalogPartitionSpec partitionSpec)
+ throws CatalogException {
return false;
}
@@ -316,7 +362,8 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException {
+ public CatalogFunction getFunction(ObjectPath functionPath)
+ throws FunctionNotExistException, CatalogException {
throw new FunctionNotExistException(getName(), functionPath);
}
@@ -324,5 +371,4 @@ public class KuduCatalog extends AbstractReadOnlyCatalog {
public boolean functionExists(ObjectPath functionPath) throws CatalogException {
return false;
}
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableFactory.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableFactory.java
index c46ac85..f4eab75 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableFactory.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableFactory.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.api.java.tuple.Tuple2;
@@ -30,15 +31,37 @@ import org.apache.flink.table.factories.TableSinkFactory;
import org.apache.flink.table.factories.TableSourceFactory;
import org.apache.flink.types.Row;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import static org.apache.flink.table.descriptors.ConnectorDescriptorValidator.CONNECTOR_TYPE;
-import static org.apache.flink.table.descriptors.DescriptorProperties.*;
-import static org.apache.flink.table.descriptors.Rowtime.*;
-import static org.apache.flink.table.descriptors.Schema.*;
+import static org.apache.flink.table.descriptors.DescriptorProperties.EXPR;
+import static org.apache.flink.table.descriptors.DescriptorProperties.WATERMARK;
+import static org.apache.flink.table.descriptors.DescriptorProperties.WATERMARK_ROWTIME;
+import static org.apache.flink.table.descriptors.DescriptorProperties.WATERMARK_STRATEGY_DATA_TYPE;
+import static org.apache.flink.table.descriptors.DescriptorProperties.WATERMARK_STRATEGY_EXPR;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_CLASS;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_FROM;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_SERIALIZED;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_TYPE;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_CLASS;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_DELAY;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_SERIALIZED;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_TYPE;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_DATA_TYPE;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_FROM;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_NAME;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_PROCTIME;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_TYPE;
import static org.apache.flink.util.Preconditions.checkNotNull;
-public class KuduTableFactory implements TableSourceFactory<Row>, TableSinkFactory<Tuple2<Boolean, Row>> {
+/** Factory for Kudu table source/sink impls. */
+public class KuduTableFactory
+ implements TableSourceFactory<Row>, TableSinkFactory<Tuple2<Boolean, Row>> {
public static final String KUDU_TABLE = "kudu.table";
public static final String KUDU_MASTERS = "kudu.masters";
@@ -114,13 +137,14 @@ public class KuduTableFactory implements TableSourceFactory<Row>, TableSinkFacto
return createTableSource(tableName, table.getSchema(), table.getOptions());
}
- private KuduTableSource createTableSource(String tableName, TableSchema schema, Map<String, String> props) {
+ private KuduTableSource createTableSource(
+ String tableName, TableSchema schema, Map<String, String> props) {
String masterAddresses = props.get(KUDU_MASTERS);
TableSchema physicalSchema = KuduTableUtils.getSchemaWithSqlTimestamp(schema);
KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, schema, props);
- KuduReaderConfig.Builder configBuilder = KuduReaderConfig.Builder
- .setMasters(masterAddresses);
+ KuduReaderConfig.Builder configBuilder =
+ KuduReaderConfig.Builder.setMasters(masterAddresses);
return new KuduTableSource(configBuilder, tableInfo, physicalSchema, null, null);
}
@@ -132,15 +156,16 @@ public class KuduTableFactory implements TableSourceFactory<Row>, TableSinkFacto
return createTableSink(tableName, table.getSchema(), table.toProperties());
}
- private KuduTableSink createTableSink(String tableName, TableSchema schema, Map<String, String> props) {
+ private KuduTableSink createTableSink(
+ String tableName, TableSchema schema, Map<String, String> props) {
DescriptorProperties properties = new DescriptorProperties();
properties.putProperties(props);
String masterAddresses = props.get(KUDU_MASTERS);
TableSchema physicalSchema = KuduTableUtils.getSchemaWithSqlTimestamp(schema);
KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, schema, props);
- KuduWriterConfig.Builder configBuilder = KuduWriterConfig.Builder
- .setMasters(masterAddresses);
+ KuduWriterConfig.Builder configBuilder =
+ KuduWriterConfig.Builder.setMasters(masterAddresses);
Optional<Long> operationTimeout = properties.getOptionalLong(KUDU_OPERATION_TIMEOUT);
Optional<Integer> flushInterval = properties.getOptionalInt(KUDU_FLUSH_INTERVAL);
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSink.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSink.java
index 5ada84e..c867343 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSink.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSink.java
@@ -32,44 +32,63 @@ import org.apache.flink.types.Row;
import java.util.Objects;
+/** Table API Kudu sink implementation. */
public class KuduTableSink implements UpsertStreamTableSink<Row> {
private final KuduWriterConfig.Builder writerConfigBuilder;
private final TableSchema flinkSchema;
private final KuduTableInfo tableInfo;
- public KuduTableSink(KuduWriterConfig.Builder configBuilder, KuduTableInfo tableInfo, TableSchema flinkSchema) {
+ public KuduTableSink(
+ KuduWriterConfig.Builder configBuilder,
+ KuduTableInfo tableInfo,
+ TableSchema flinkSchema) {
this.writerConfigBuilder = configBuilder;
this.tableInfo = tableInfo;
this.flinkSchema = flinkSchema;
}
@Override
- public void setKeyFields(String[] keyFields) { /* this has no effect */}
+ public void setKeyFields(String[] keyFields) {
+ /* this has no effect */
+ }
@Override
- public void setIsAppendOnly(Boolean isAppendOnly) { /* this has no effect */}
+ public void setIsAppendOnly(Boolean isAppendOnly) {
+ /* this has no effect */
+ }
@Override
- public TypeInformation<Row> getRecordType() { return flinkSchema.toRowType(); }
+ public TypeInformation<Row> getRecordType() {
+ return flinkSchema.toRowType();
+ }
@Override
public DataStreamSink<?> consumeDataStream(DataStream<Tuple2<Boolean, Row>> dataStreamTuple) {
- KuduSink upsertKuduSink = new KuduSink(writerConfigBuilder.build(), tableInfo, new UpsertOperationMapper(getTableSchema().getFieldNames()));
+ KuduSink upsertKuduSink =
+ new KuduSink(
+ writerConfigBuilder.build(),
+ tableInfo,
+ new UpsertOperationMapper(getTableSchema().getFieldNames()));
return dataStreamTuple
.addSink(upsertKuduSink)
.setParallelism(dataStreamTuple.getParallelism())
- .name(TableConnectorUtils.generateRuntimeName(this.getClass(), getTableSchema().getFieldNames()));
+ .name(
+ TableConnectorUtils.generateRuntimeName(
+ this.getClass(), getTableSchema().getFieldNames()));
}
@Override
- public TableSink<Tuple2<Boolean, Row>> configure(String[] fieldNames, TypeInformation<?>[] fieldTypes) {
+ public TableSink<Tuple2<Boolean, Row>> configure(
+ String[] fieldNames, TypeInformation<?>[] fieldTypes) {
return new KuduTableSink(writerConfigBuilder, tableInfo, flinkSchema);
}
@Override
- public TableSchema getTableSchema() { return flinkSchema; }
+ public TableSchema getTableSchema() {
+ return flinkSchema;
+ }
@Override
public boolean equals(Object o) {
@@ -80,9 +99,9 @@ public class KuduTableSink implements UpsertStreamTableSink<Row> {
return false;
}
KuduTableSink that = (KuduTableSink) o;
- return this.writerConfigBuilder.equals(that.writerConfigBuilder) &&
- this.flinkSchema.equals(that.flinkSchema) &&
- this.tableInfo.equals(that.tableInfo);
+ return this.writerConfigBuilder.equals(that.writerConfigBuilder)
+ && this.flinkSchema.equals(that.flinkSchema)
+ && this.tableInfo.equals(that.tableInfo);
}
@Override
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSource.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSource.java
index 287dfb4..c750db4 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSource.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/KuduTableSource.java
@@ -20,7 +20,7 @@ package org.apache.flink.connectors.kudu.table;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.connectors.kudu.format.KuduRowInputFormat;
import org.apache.flink.streaming.api.datastream.DataStream;
@@ -28,22 +28,36 @@ import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.expressions.Expression;
-import org.apache.flink.table.sources.*;
+import org.apache.flink.table.sources.FilterableTableSource;
+import org.apache.flink.table.sources.LimitableTableSource;
+import org.apache.flink.table.sources.ProjectableTableSource;
+import org.apache.flink.table.sources.StreamTableSource;
+import org.apache.flink.table.sources.TableSource;
import org.apache.flink.table.types.DataType;
import org.apache.flink.table.types.logical.RowType;
import org.apache.flink.table.types.utils.TypeConversions;
import org.apache.flink.types.Row;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
-import java.util.*;
-import static org.apache.flink.connectors.kudu.table.utils.KuduTableUtils.toKuduFilterInfo;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Optional;
-public class KuduTableSource implements StreamTableSource<Row>,
- LimitableTableSource<Row>, ProjectableTableSource<Row>, FilterableTableSource<Row> {
+import static org.apache.flink.connectors.kudu.table.utils.KuduTableUtils.toKuduFilterInfo;
+/** DataStream source implementation for Kudu. */
+public class KuduTableSource
+ implements StreamTableSource<Row>,
+ LimitableTableSource<Row>,
+ ProjectableTableSource<Row>,
+ FilterableTableSource<Row> {
private static final Logger LOG = LoggerFactory.getLogger(KuduTableSource.class);
@@ -52,14 +66,17 @@ public class KuduTableSource implements StreamTableSource<Row>,
private final TableSchema flinkSchema;
private final String[] projectedFields;
// predicate expression to apply
- @Nullable
- private final List<KuduFilterInfo> predicates;
+ @Nullable private final List<KuduFilterInfo> predicates;
private boolean isFilterPushedDown;
private KuduRowInputFormat kuduRowInputFormat;
- public KuduTableSource(KuduReaderConfig.Builder configBuilder, KuduTableInfo tableInfo,
- TableSchema flinkSchema, List<KuduFilterInfo> predicates, String[] projectedFields) {
+ public KuduTableSource(
+ KuduReaderConfig.Builder configBuilder,
+ KuduTableInfo tableInfo,
+ TableSchema flinkSchema,
+ List<KuduFilterInfo> predicates,
+ String[] projectedFields) {
this.configBuilder = configBuilder;
this.tableInfo = tableInfo;
this.flinkSchema = flinkSchema;
@@ -68,9 +85,13 @@ public class KuduTableSource implements StreamTableSource<Row>,
if (predicates != null && predicates.size() != 0) {
this.isFilterPushedDown = true;
}
- this.kuduRowInputFormat = new KuduRowInputFormat(configBuilder.build(), new RowResultRowConvertor(), tableInfo,
- predicates == null ? Collections.emptyList() : predicates,
- projectedFields == null ? null : Arrays.asList(projectedFields));
+ this.kuduRowInputFormat =
+ new KuduRowInputFormat(
+ configBuilder.build(),
+ new RowResultRowConverter(),
+ tableInfo,
+ predicates == null ? Collections.emptyList() : predicates,
+ projectedFields == null ? null : Arrays.asList(projectedFields));
}
@Override
@@ -80,12 +101,17 @@ public class KuduTableSource implements StreamTableSource<Row>,
@Override
public DataStream<Row> getDataStream(StreamExecutionEnvironment env) {
- KuduRowInputFormat inputFormat = new KuduRowInputFormat(configBuilder.build(), new RowResultRowConvertor(),
- tableInfo,
- predicates == null ? Collections.emptyList() : predicates,
- projectedFields == null ? null : Arrays.asList(projectedFields));
- return env.createInput(inputFormat,
- (TypeInformation<Row>) TypeConversions.fromDataTypeToLegacyInfo(getProducedDataType()))
+ KuduRowInputFormat inputFormat =
+ new KuduRowInputFormat(
+ configBuilder.build(),
+ new RowResultRowConverter(),
+ tableInfo,
+ predicates == null ? Collections.emptyList() : predicates,
+ projectedFields == null ? null : Arrays.asList(projectedFields));
+ return env.createInput(
+ inputFormat,
+ (TypeInformation<Row>)
+ TypeConversions.fromDataTypeToLegacyInfo(getProducedDataType()))
.name(explainSource());
}
@@ -107,13 +133,9 @@ public class KuduTableSource implements StreamTableSource<Row>,
DataTypes.Field[] fields = new DataTypes.Field[projectedFields.length];
for (int i = 0; i < fields.length; i++) {
String fieldName = projectedFields[i];
- fields[i] = DataTypes.FIELD(
- fieldName,
- flinkSchema
- .getTableColumn(fieldName)
- .get()
- .getType()
- );
+ fields[i] =
+ DataTypes.FIELD(
+ fieldName, flinkSchema.getTableColumn(fieldName).get().getType());
}
return DataTypes.ROW(fields);
}
@@ -126,8 +148,12 @@ public class KuduTableSource implements StreamTableSource<Row>,
@Override
public TableSource<Row> applyLimit(long l) {
- return new KuduTableSource(configBuilder.setRowLimit((int) l), tableInfo, flinkSchema,
- predicates, projectedFields);
+ return new KuduTableSource(
+ configBuilder.setRowLimit((int) l),
+ tableInfo,
+ flinkSchema,
+ predicates,
+ projectedFields);
}
@Override
@@ -149,23 +175,33 @@ public class KuduTableSource implements StreamTableSource<Row>,
Expression predicate = predicatesIter.next();
Optional<KuduFilterInfo> kuduPred = toKuduFilterInfo(predicate);
if (kuduPred != null && kuduPred.isPresent()) {
- LOG.debug("Predicate [{}] converted into KuduFilterInfo and pushed into " +
- "KuduTable [{}].", predicate, tableInfo.getName());
+ LOG.debug(
+ "Predicate [{}] converted into KuduFilterInfo and pushed into "
+ + "KuduTable [{}].",
+ predicate,
+ tableInfo.getName());
kuduPredicates.add(kuduPred.get());
predicatesIter.remove();
} else {
- LOG.debug("Predicate [{}] could not be pushed into KuduFilterInfo for KuduTable [{}].",
- predicate, tableInfo.getName());
+ LOG.debug(
+ "Predicate [{}] could not be pushed into KuduFilterInfo for KuduTable [{}].",
+ predicate,
+ tableInfo.getName());
}
}
- return new KuduTableSource(configBuilder, tableInfo, flinkSchema, kuduPredicates, projectedFields);
+ return new KuduTableSource(
+ configBuilder, tableInfo, flinkSchema, kuduPredicates, projectedFields);
}
@Override
public String explainSource() {
- return "KuduTableSource[schema=" + Arrays.toString(getTableSchema().getFieldNames()) +
- ", filter=" + predicateString() +
- (projectedFields != null ? ", projectFields=" + Arrays.toString(projectedFields) + "]" : "]");
+ return "KuduTableSource[schema="
+ + Arrays.toString(getTableSchema().getFieldNames())
+ + ", filter="
+ + predicateString()
+ + (projectedFields != null
+ ? ", projectFields=" + Arrays.toString(projectedFields) + "]"
+ : "]");
}
private String predicateString() {
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/UpsertOperationMapper.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/UpsertOperationMapper.java
index 31c8d79..5813fee 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/UpsertOperationMapper.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/UpsertOperationMapper.java
@@ -14,17 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.annotation.Internal;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.connectors.kudu.connector.writer.AbstractSingleOperationMapper;
import org.apache.flink.types.Row;
+
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.Operation;
import java.util.Optional;
+/** Logic to map a Flink DataStream upsert record to a Kudu-compatible format. */
@Internal
public class UpsertOperationMapper extends AbstractSingleOperationMapper<Tuple2<Boolean, Row>> {
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSink.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSink.java
index 179c01f..747e47b 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSink.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSink.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -30,16 +31,16 @@ import org.apache.flink.util.Preconditions;
import java.util.Objects;
-/**
- * A {@link KuduDynamicTableSink} for Kudu.
- */
+/** A {@link KuduDynamicTableSink} for Kudu. */
public class KuduDynamicTableSink implements DynamicTableSink {
private final KuduWriterConfig.Builder writerConfigBuilder;
private final TableSchema flinkSchema;
private final KuduTableInfo tableInfo;
- public KuduDynamicTableSink(KuduWriterConfig.Builder writerConfigBuilder, TableSchema flinkSchema,
- KuduTableInfo tableInfo) {
+ public KuduDynamicTableSink(
+ KuduWriterConfig.Builder writerConfigBuilder,
+ TableSchema flinkSchema,
+ KuduTableInfo tableInfo) {
this.writerConfigBuilder = writerConfigBuilder;
this.flinkSchema = flinkSchema;
this.tableInfo = tableInfo;
@@ -48,17 +49,27 @@ public class KuduDynamicTableSink implements DynamicTableSink {
@Override
public ChangelogMode getChangelogMode(ChangelogMode requestedMode) {
this.validatePrimaryKey(requestedMode);
- return ChangelogMode.newBuilder().addContainedKind(RowKind.INSERT).addContainedKind(RowKind.DELETE).addContainedKind(RowKind.UPDATE_AFTER).build();
+ return ChangelogMode.newBuilder()
+ .addContainedKind(RowKind.INSERT)
+ .addContainedKind(RowKind.DELETE)
+ .addContainedKind(RowKind.UPDATE_AFTER)
+ .build();
}
private void validatePrimaryKey(ChangelogMode requestedMode) {
- Preconditions.checkState(ChangelogMode.insertOnly().equals(requestedMode) || this.tableInfo.getSchema().getPrimaryKeyColumnCount() != 0, "please declare primary key for sink table when query contains update/delete record.");
+ Preconditions.checkState(
+ ChangelogMode.insertOnly().equals(requestedMode)
+ || this.tableInfo.getSchema().getPrimaryKeyColumnCount() != 0,
+ "please declare primary key for sink table when query contains update/delete record.");
}
@Override
public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
- KuduSink<RowData> upsertKuduSink = new KuduSink<>(writerConfigBuilder.build(), tableInfo,
- new RowDataUpsertOperationMapper(flinkSchema));
+ KuduSink<RowData> upsertKuduSink =
+ new KuduSink<>(
+ writerConfigBuilder.build(),
+ tableInfo,
+ new RowDataUpsertOperationMapper(flinkSchema));
return SinkFunctionProvider.of(upsertKuduSink);
}
@@ -74,11 +85,16 @@ public class KuduDynamicTableSink implements DynamicTableSink {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
KuduDynamicTableSink that = (KuduDynamicTableSink) o;
- return Objects.equals(writerConfigBuilder, that.writerConfigBuilder) && Objects.equals(flinkSchema,
- that.flinkSchema) && Objects.equals(tableInfo, that.tableInfo);
+ return Objects.equals(writerConfigBuilder, that.writerConfigBuilder)
+ && Objects.equals(flinkSchema, that.flinkSchema)
+ && Objects.equals(tableInfo, that.tableInfo);
}
@Override
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSource.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSource.java
index da6bebb..585c5b9 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSource.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSource.java
@@ -14,12 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowDataConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowDataConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.connectors.kudu.format.KuduRowDataInputFormat;
import org.apache.flink.connectors.kudu.table.function.lookup.KuduLookupOptions;
@@ -27,7 +27,11 @@ import org.apache.flink.connectors.kudu.table.function.lookup.KuduRowDataLookupF
import org.apache.flink.connectors.kudu.table.utils.KuduTableUtils;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.connector.ChangelogMode;
-import org.apache.flink.table.connector.source.*;
+import org.apache.flink.table.connector.source.DynamicTableSource;
+import org.apache.flink.table.connector.source.InputFormatProvider;
+import org.apache.flink.table.connector.source.LookupTableSource;
+import org.apache.flink.table.connector.source.ScanTableSource;
+import org.apache.flink.table.connector.source.TableFunctionProvider;
import org.apache.flink.table.connector.source.abilities.SupportsFilterPushDown;
import org.apache.flink.table.connector.source.abilities.SupportsLimitPushDown;
import org.apache.flink.table.connector.source.abilities.SupportsProjectionPushDown;
@@ -37,19 +41,27 @@ import org.apache.flink.table.types.FieldsDataType;
import org.apache.flink.table.types.logical.RowType;
import org.apache.flink.table.types.utils.DataTypeUtils;
import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.collections.CollectionUtils;
import org.apache.kudu.shaded.com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import static org.apache.flink.table.utils.TableSchemaUtils.containsPhysicalColumnsOnly;
-/**
- * A {@link DynamicTableSource} for Kudu.
- */
-public class KuduDynamicTableSource implements ScanTableSource, SupportsProjectionPushDown,
- SupportsLimitPushDown, LookupTableSource, SupportsFilterPushDown {
+/** A {@link DynamicTableSource} for Kudu. */
+public class KuduDynamicTableSource
+ implements ScanTableSource,
+ SupportsProjectionPushDown,
+ SupportsLimitPushDown,
+ LookupTableSource,
+ SupportsFilterPushDown {
private static final Logger LOG = LoggerFactory.getLogger(KuduDynamicTableSource.class);
private final KuduTableInfo tableInfo;
@@ -61,17 +73,23 @@ public class KuduDynamicTableSource implements ScanTableSource, SupportsProjecti
private String[] projectedFields;
private transient List<ResolvedExpression> filters;
- public KuduDynamicTableSource(KuduReaderConfig.Builder configBuilder, KuduTableInfo tableInfo,
- TableSchema physicalSchema, String[] projectedFields,
- KuduLookupOptions kuduLookupOptions) {
+ public KuduDynamicTableSource(
+ KuduReaderConfig.Builder configBuilder,
+ KuduTableInfo tableInfo,
+ TableSchema physicalSchema,
+ String[] projectedFields,
+ KuduLookupOptions kuduLookupOptions) {
this.configBuilder = configBuilder;
this.tableInfo = tableInfo;
this.physicalSchema = physicalSchema;
this.projectedFields = projectedFields;
- this.kuduRowDataInputFormat = new KuduRowDataInputFormat(configBuilder.build(),
- new RowResultRowDataConvertor(), tableInfo,
- predicates,
- projectedFields == null ? null : Lists.newArrayList(projectedFields));
+ this.kuduRowDataInputFormat =
+ new KuduRowDataInputFormat(
+ configBuilder.build(),
+ new RowResultRowDataConverter(),
+ tableInfo,
+ predicates,
+ projectedFields == null ? null : Lists.newArrayList(projectedFields));
this.kuduLookupOptions = kuduLookupOptions;
}
@@ -81,16 +99,18 @@ public class KuduDynamicTableSource implements ScanTableSource, SupportsProjecti
String[] keyNames = new String[keysLen];
for (int i = 0; i < keyNames.length; ++i) {
int[] innerKeyArr = context.getKeys()[i];
- Preconditions.checkArgument(innerKeyArr.length == 1, "Kudu only support non-nested look up keys");
+ Preconditions.checkArgument(
+ innerKeyArr.length == 1, "Kudu only support non-nested look up keys");
keyNames[i] = this.physicalSchema.getFieldNames()[innerKeyArr[0]];
}
- KuduRowDataLookupFunction rowDataLookupFunction = KuduRowDataLookupFunction.Builder.options()
- .keyNames(keyNames)
- .kuduReaderConfig(configBuilder.build())
- .projectedFields(projectedFields)
- .tableInfo(tableInfo)
- .kuduLookupOptions(kuduLookupOptions)
- .build();
+ KuduRowDataLookupFunction rowDataLookupFunction =
+ KuduRowDataLookupFunction.Builder.options()
+ .keyNames(keyNames)
+ .kuduReaderConfig(configBuilder.build())
+ .projectedFields(projectedFields)
+ .tableInfo(tableInfo)
+ .kuduLookupOptions(kuduLookupOptions)
+ .build();
return TableFunctionProvider.of(rowDataLookupFunction);
}
@@ -107,20 +127,26 @@ public class KuduDynamicTableSource implements ScanTableSource, SupportsProjecti
if (kuduFilterInfo != null && kuduFilterInfo.isPresent()) {
this.predicates.add(kuduFilterInfo.get());
}
-
}
}
- KuduRowDataInputFormat inputFormat = new KuduRowDataInputFormat(configBuilder.build(),
- new RowResultRowDataConvertor(), tableInfo,
- this.predicates,
- projectedFields == null ? null : Lists.newArrayList(projectedFields));
+ KuduRowDataInputFormat inputFormat =
+ new KuduRowDataInputFormat(
+ configBuilder.build(),
+ new RowResultRowDataConverter(),
+ tableInfo,
+ this.predicates,
+ projectedFields == null ? null : Lists.newArrayList(projectedFields));
return InputFormatProvider.of(inputFormat);
}
@Override
public DynamicTableSource copy() {
- return new KuduDynamicTableSource(this.configBuilder, this.tableInfo, this.physicalSchema,
- this.projectedFields, this.kuduLookupOptions);
+ return new KuduDynamicTableSource(
+ this.configBuilder,
+ this.tableInfo,
+ this.physicalSchema,
+ this.projectedFields,
+ this.kuduLookupOptions);
}
@Override
@@ -159,16 +185,34 @@ public class KuduDynamicTableSource implements ScanTableSource, SupportsProjecti
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
KuduDynamicTableSource that = (KuduDynamicTableSource) o;
- return Objects.equals(configBuilder, that.configBuilder) && Objects.equals(tableInfo, that.tableInfo) && Objects.equals(physicalSchema, that.physicalSchema) && Arrays.equals(projectedFields, that.projectedFields) && Objects.equals(kuduLookupOptions, that.kuduLookupOptions) && Objects.equals(kuduRowDataInputFormat, that.kuduRowDataInputFormat) && Objects.equals(filters, that.filters) && Objects.equals(predicates, that.predicates);
+ return Objects.equals(configBuilder, that.configBuilder)
+ && Objects.equals(tableInfo, that.tableInfo)
+ && Objects.equals(physicalSchema, that.physicalSchema)
+ && Arrays.equals(projectedFields, that.projectedFields)
+ && Objects.equals(kuduLookupOptions, that.kuduLookupOptions)
+ && Objects.equals(kuduRowDataInputFormat, that.kuduRowDataInputFormat)
+ && Objects.equals(filters, that.filters)
+ && Objects.equals(predicates, that.predicates);
}
@Override
public int hashCode() {
- int result = Objects.hash(configBuilder, tableInfo, physicalSchema,
- kuduLookupOptions, kuduRowDataInputFormat, filters, predicates);
+ int result =
+ Objects.hash(
+ configBuilder,
+ tableInfo,
+ physicalSchema,
+ kuduLookupOptions,
+ kuduRowDataInputFormat,
+ filters,
+ predicates);
result = 31 * result + Arrays.hashCode(projectedFields);
return result;
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSourceSinkFactory.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSourceSinkFactory.java
index 6fab41f..879fc1a 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSourceSinkFactory.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicTableSourceSinkFactory.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
import org.apache.flink.configuration.ConfigOption;
@@ -30,128 +31,110 @@ import org.apache.flink.table.connector.source.DynamicTableSource;
import org.apache.flink.table.factories.DynamicTableSinkFactory;
import org.apache.flink.table.factories.DynamicTableSourceFactory;
import org.apache.flink.table.factories.FactoryUtil;
+
import org.apache.kudu.shaded.com.google.common.collect.Sets;
import java.util.Optional;
import java.util.Set;
/**
- * Factory for creating configured instances of {@link KuduDynamicTableSource}/{@link KuduDynamicTableSink} in
- * a stream environment.
+ * Factory for creating configured instances of {@link KuduDynamicTableSource}/{@link
+ * KuduDynamicTableSink} in a stream environment.
*/
-public class KuduDynamicTableSourceSinkFactory implements DynamicTableSourceFactory, DynamicTableSinkFactory {
+public class KuduDynamicTableSourceSinkFactory
+ implements DynamicTableSourceFactory, DynamicTableSinkFactory {
public static final String IDENTIFIER = "kudu";
- public static final ConfigOption<String> KUDU_TABLE = ConfigOptions
- .key("kudu.table")
- .stringType()
- .noDefaultValue()
- .withDescription("kudu's table name");
+ public static final ConfigOption<String> KUDU_TABLE =
+ ConfigOptions.key("kudu.table")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("kudu's table name");
public static final ConfigOption<String> KUDU_MASTERS =
- ConfigOptions
- .key("kudu.masters")
+ ConfigOptions.key("kudu.masters")
.stringType()
.noDefaultValue()
.withDescription("kudu's master server address");
-
public static final ConfigOption<String> KUDU_HASH_COLS =
- ConfigOptions
- .key("kudu.hash-columns")
+ ConfigOptions.key("kudu.hash-columns")
.stringType()
.noDefaultValue()
.withDescription("kudu's hash columns");
public static final ConfigOption<Integer> KUDU_REPLICAS =
- ConfigOptions
- .key("kudu.replicas")
+ ConfigOptions.key("kudu.replicas")
.intType()
.defaultValue(3)
.withDescription("kudu's replica nums");
public static final ConfigOption<Integer> KUDU_MAX_BUFFER_SIZE =
- ConfigOptions
- .key("kudu.max-buffer-size")
+ ConfigOptions.key("kudu.max-buffer-size")
.intType()
.noDefaultValue()
.withDescription("kudu's max buffer size");
public static final ConfigOption<Integer> KUDU_FLUSH_INTERVAL =
- ConfigOptions
- .key("kudu.flush-interval")
+ ConfigOptions.key("kudu.flush-interval")
.intType()
.noDefaultValue()
.withDescription("kudu's data flush interval");
public static final ConfigOption<Long> KUDU_OPERATION_TIMEOUT =
- ConfigOptions
- .key("kudu.operation-timeout")
+ ConfigOptions.key("kudu.operation-timeout")
.longType()
.noDefaultValue()
.withDescription("kudu's operation timeout");
public static final ConfigOption<Boolean> KUDU_IGNORE_NOT_FOUND =
- ConfigOptions
- .key("kudu.ignore-not-found")
+ ConfigOptions.key("kudu.ignore-not-found")
.booleanType()
.noDefaultValue()
.withDescription("if true, ignore all not found rows");
public static final ConfigOption<Boolean> KUDU_IGNORE_DUPLICATE =
- ConfigOptions
- .key("kudu.ignore-not-found")
+ ConfigOptions.key("kudu.ignore-not-found")
.booleanType()
.noDefaultValue()
.withDescription("if true, ignore all dulicate rows");
- /**
- * hash partition bucket nums
- */
public static final ConfigOption<Integer> KUDU_HASH_PARTITION_NUMS =
- ConfigOptions
- .key("kudu.hash-partition-nums")
+ ConfigOptions.key("kudu.hash-partition-nums")
.intType()
.defaultValue(KUDU_REPLICAS.defaultValue() * 2)
- .withDescription("kudu's hash partition bucket nums, defaultValue is 2 * replica nums");
+ .withDescription(
+ "kudu's hash partition bucket nums, defaultValue is 2 * replica nums");
public static final ConfigOption<String> KUDU_PRIMARY_KEY_COLS =
- ConfigOptions
- .key("kudu.primary-key-columns")
+ ConfigOptions.key("kudu.primary-key-columns")
.stringType()
.noDefaultValue()
.withDescription("kudu's primary key, primary key must be ordered");
-
public static final ConfigOption<Integer> KUDU_SCAN_ROW_SIZE =
- ConfigOptions
- .key("kudu.scan.row-size")
+ ConfigOptions.key("kudu.scan.row-size")
.intType()
.defaultValue(0)
.withDescription("kudu's scan row size");
- /**
- * lookup cache config
- */
public static final ConfigOption<Long> KUDU_LOOKUP_CACHE_MAX_ROWS =
- ConfigOptions
- .key("kudu.lookup.cache.max-rows")
+ ConfigOptions.key("kudu.lookup.cache.max-rows")
.longType()
.defaultValue(-1L)
- .withDescription("the max number of rows of lookup cache, over this value, the oldest rows will " +
- "be eliminated. \"cache.max-rows\" and \"cache.ttl\" options must all be specified if any" +
- " of them is " +
- "specified. Cache is not enabled as default.");
+ .withDescription(
+ "the max number of rows of lookup cache, over this value, the oldest rows will "
+ + "be eliminated. \"cache.max-rows\" and \"cache.ttl\" options must all be specified if any"
+ + " of them is "
+ + "specified. Cache is not enabled as default.");
public static final ConfigOption<Long> KUDU_LOOKUP_CACHE_TTL =
- ConfigOptions
- .key("kudu.lookup.cache.ttl")
+ ConfigOptions.key("kudu.lookup.cache.ttl")
.longType()
.defaultValue(-1L)
.withDescription("the cache time to live.");
public static final ConfigOption<Integer> KUDU_LOOKUP_MAX_RETRIES =
- ConfigOptions
- .key("kudu.lookup.max-retries")
+ ConfigOptions.key("kudu.lookup.max-retries")
.intType()
.defaultValue(3)
.withDescription("the max retry times if lookup database failed.");
@@ -168,11 +151,12 @@ public class KuduDynamicTableSourceSinkFactory implements DynamicTableSourceFact
Optional<Boolean> ignoreDuplicate = config.getOptional(KUDU_IGNORE_DUPLICATE);
TableSchema schema = context.getCatalogTable().getSchema();
TableSchema physicalSchema = KuduTableUtils.getSchemaWithSqlTimestamp(schema);
- KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, schema,
- context.getCatalogTable().toProperties());
+ KuduTableInfo tableInfo =
+ KuduTableUtils.createTableInfo(
+ tableName, schema, context.getCatalogTable().toProperties());
- KuduWriterConfig.Builder configBuilder = KuduWriterConfig.Builder
- .setMasters(masterAddresses);
+ KuduWriterConfig.Builder configBuilder =
+ KuduWriterConfig.Builder.setMasters(masterAddresses);
operationTimeout.ifPresent(configBuilder::setOperationTimeout);
flushInterval.ifPresent(configBuilder::setFlushInterval);
bufferSize.ifPresent(configBuilder::setMaxBufferSize);
@@ -181,18 +165,11 @@ public class KuduDynamicTableSourceSinkFactory implements DynamicTableSourceFact
return new KuduDynamicTableSink(configBuilder, physicalSchema, tableInfo);
}
- /**
- * get readableConfig
- *
- * @param context
- * @return {@link ReadableConfig}
- */
private ReadableConfig getReadableConfig(Context context) {
FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
return helper.getOptions();
}
-
@Override
public DynamicTableSource createDynamicTableSource(Context context) {
ReadableConfig config = getReadableConfig(context);
@@ -204,20 +181,26 @@ public class KuduDynamicTableSourceSinkFactory implements DynamicTableSourceFact
int kuduMaxReties = config.get(KUDU_LOOKUP_MAX_RETRIES);
// build kudu lookup options
- KuduLookupOptions kuduLookupOptions = KuduLookupOptions.Builder.options().withCacheMaxSize(kuduCacheMaxRows)
- .withCacheExpireMs(kuduCacheTtl)
- .withMaxRetryTimes(kuduMaxReties)
- .build();
+ KuduLookupOptions kuduLookupOptions =
+ KuduLookupOptions.Builder.options()
+ .withCacheMaxSize(kuduCacheMaxRows)
+ .withCacheExpireMs(kuduCacheTtl)
+ .withMaxRetryTimes(kuduMaxReties)
+ .build();
TableSchema schema = context.getCatalogTable().getSchema();
TableSchema physicalSchema = KuduTableUtils.getSchemaWithSqlTimestamp(schema);
- KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(config.get(KUDU_TABLE), schema,
- context.getCatalogTable().toProperties());
-
- KuduReaderConfig.Builder configBuilder = KuduReaderConfig.Builder
- .setMasters(masterAddresses)
- .setRowLimit(scanRowSize);
- return new KuduDynamicTableSource(configBuilder, tableInfo, physicalSchema, physicalSchema.getFieldNames(),
+ KuduTableInfo tableInfo =
+ KuduTableUtils.createTableInfo(
+ config.get(KUDU_TABLE), schema, context.getCatalogTable().toProperties());
+
+ KuduReaderConfig.Builder configBuilder =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).setRowLimit(scanRowSize);
+ return new KuduDynamicTableSource(
+ configBuilder,
+ tableInfo,
+ physicalSchema,
+ physicalSchema.getFieldNames(),
kuduLookupOptions);
}
@@ -233,11 +216,20 @@ public class KuduDynamicTableSourceSinkFactory implements DynamicTableSourceFact
@Override
public Set<ConfigOption<?>> optionalOptions() {
- return Sets.newHashSet(KUDU_HASH_COLS, KUDU_HASH_PARTITION_NUMS,
- KUDU_PRIMARY_KEY_COLS, KUDU_SCAN_ROW_SIZE, KUDU_REPLICAS,
- KUDU_MAX_BUFFER_SIZE, KUDU_MAX_BUFFER_SIZE, KUDU_OPERATION_TIMEOUT,
- KUDU_IGNORE_NOT_FOUND, KUDU_IGNORE_DUPLICATE,
- //lookup
- KUDU_LOOKUP_CACHE_MAX_ROWS, KUDU_LOOKUP_CACHE_TTL, KUDU_LOOKUP_MAX_RETRIES);
+ return Sets.newHashSet(
+ KUDU_HASH_COLS,
+ KUDU_HASH_PARTITION_NUMS,
+ KUDU_PRIMARY_KEY_COLS,
+ KUDU_SCAN_ROW_SIZE,
+ KUDU_REPLICAS,
+ KUDU_MAX_BUFFER_SIZE,
+ KUDU_MAX_BUFFER_SIZE,
+ KUDU_OPERATION_TIMEOUT,
+ KUDU_IGNORE_NOT_FOUND,
+ KUDU_IGNORE_DUPLICATE,
+ // lookup
+ KUDU_LOOKUP_CACHE_MAX_ROWS,
+ KUDU_LOOKUP_CACHE_TTL,
+ KUDU_LOOKUP_MAX_RETRIES);
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduCatalogFactory.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduCatalogFactory.java
index 8ad9350..3b04e9b 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduCatalogFactory.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduCatalogFactory.java
@@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic.catalog;
import org.apache.flink.annotation.Internal;
@@ -22,6 +23,7 @@ import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.table.catalog.Catalog;
import org.apache.flink.table.factories.CatalogFactory;
import org.apache.flink.table.factories.FactoryUtil;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,9 +34,7 @@ import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSou
import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_MASTERS;
import static org.apache.flink.table.factories.FactoryUtil.PROPERTY_VERSION;
-/**
- * Factory for {@link KuduDynamicCatalog}.
- */
+/** Factory for {@link KuduDynamicCatalog}. */
@Internal
public class KuduCatalogFactory implements CatalogFactory {
@@ -64,8 +64,6 @@ public class KuduCatalogFactory implements CatalogFactory {
final FactoryUtil.CatalogFactoryHelper helper =
FactoryUtil.createCatalogFactoryHelper(this, context);
helper.validate();
- return new KuduDynamicCatalog(context.getName(),
- helper.getOptions().get(KUDU_MASTERS));
+ return new KuduDynamicCatalog(context.getName(), helper.getOptions().get(KUDU_MASTERS));
}
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduDynamicCatalog.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduDynamicCatalog.java
index 3dff23c..5cf35af 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduDynamicCatalog.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/dynamic/catalog/KuduDynamicCatalog.java
@@ -15,21 +15,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.flink.connectors.kudu.table.dynamic.catalog;
+package org.apache.flink.connectors.kudu.table.dynamic.catalog;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
import org.apache.flink.connectors.kudu.table.AbstractReadOnlyCatalog;
import org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory;
import org.apache.flink.connectors.kudu.table.utils.KuduTableUtils;
import org.apache.flink.table.api.TableSchema;
-import org.apache.flink.table.catalog.*;
-import org.apache.flink.table.catalog.exceptions.*;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.CatalogTableImpl;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
import org.apache.flink.table.expressions.Expression;
import org.apache.flink.table.factories.Factory;
import org.apache.flink.util.StringUtils;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.client.AlterTableOptions;
import org.apache.kudu.client.KuduClient;
@@ -40,25 +52,35 @@ import org.apache.kudu.shaded.com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.stream.Collectors;
-import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.*;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_HASH_COLS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_HASH_PARTITION_NUMS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_PRIMARY_KEY_COLS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_REPLICAS;
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkNotNull;
-/**
- * Catalog for reading and creating Kudu tables.
- */
+/** Catalog for reading and creating Kudu tables. */
public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
private static final Logger LOG = LoggerFactory.getLogger(KuduDynamicCatalog.class);
- private final KuduDynamicTableSourceSinkFactory tableFactory = new KuduDynamicTableSourceSinkFactory();
+ private final KuduDynamicTableSourceSinkFactory tableFactory =
+ new KuduDynamicTableSourceSinkFactory();
private final String kuduMasters;
private final KuduClient kuduClient;
/**
- * Create a new {@link KuduDynamicCatalog} with the specified catalog name and kudu master addresses.
+ * Create a new {@link KuduDynamicCatalog} with the specified catalog name and kudu master
+ * addresses.
*
* @param catalogName Name of the catalog (used by the table environment)
* @param kuduMasters Connection address to Kudu
@@ -92,8 +114,7 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public void open() {
- }
+ public void open() {}
@Override
public void close() {
@@ -111,8 +132,11 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public List<String> listTables(String databaseName) throws DatabaseNotExistException, CatalogException {
- checkArgument(!StringUtils.isNullOrWhitespaceOnly(databaseName), "databaseName cannot be null or empty");
+ public List<String> listTables(String databaseName)
+ throws DatabaseNotExistException, CatalogException {
+ checkArgument(
+ !StringUtils.isNullOrWhitespaceOnly(databaseName),
+ "databaseName cannot be null or empty");
if (!databaseExists(databaseName)) {
throw new DatabaseNotExistException(getName(), databaseName);
@@ -148,10 +172,12 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
try {
KuduTable kuduTable = kuduClient.openTable(tableName);
// fixme base on TableSchema, TableSchema needs to be upgraded to ResolvedSchema
- CatalogTableImpl table = new CatalogTableImpl(
- KuduTableUtils.kuduToFlinkSchema(kuduTable.getSchema()),
- createTableProperties(tableName, kuduTable.getSchema().getPrimaryKeyColumns()),
- tableName);
+ CatalogTableImpl table =
+ new CatalogTableImpl(
+ KuduTableUtils.kuduToFlinkSchema(kuduTable.getSchema()),
+ createTableProperties(
+ tableName, kuduTable.getSchema().getPrimaryKeyColumns()),
+ tableName);
return table;
} catch (KuduException e) {
@@ -159,17 +185,22 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
}
- protected Map<String, String> createTableProperties(String tableName, List<ColumnSchema> primaryKeyColumns) {
+ protected Map<String, String> createTableProperties(
+ String tableName, List<ColumnSchema> primaryKeyColumns) {
Map<String, String> props = new HashMap<>();
props.put(KuduDynamicTableSourceSinkFactory.KUDU_MASTERS.key(), kuduMasters);
- String primaryKeyNames = primaryKeyColumns.stream().map(ColumnSchema::getName).collect(Collectors.joining(","));
+ String primaryKeyNames =
+ primaryKeyColumns.stream()
+ .map(ColumnSchema::getName)
+ .collect(Collectors.joining(","));
props.put(KUDU_PRIMARY_KEY_COLS.key(), primaryKeyNames);
props.put(KuduDynamicTableSourceSinkFactory.KUDU_TABLE.key(), tableName);
return props;
}
@Override
- public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+ throws TableNotExistException {
String tableName = tablePath.getObjectName();
try {
if (tableExists(tablePath)) {
@@ -183,7 +214,8 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists) throws TableNotExistException {
+ public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+ throws TableNotExistException {
String tableName = tablePath.getObjectName();
try {
if (tableExists(tablePath)) {
@@ -196,7 +228,8 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
}
- public void createTable(KuduTableInfo tableInfo, boolean ignoreIfExists) throws CatalogException, TableAlreadyExistException {
+ public void createTable(KuduTableInfo tableInfo, boolean ignoreIfExists)
+ throws CatalogException, TableAlreadyExistException {
ObjectPath path = getObjectPath(tableInfo.getName());
if (tableExists(path)) {
if (ignoreIfExists) {
@@ -207,20 +240,25 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
try {
- kuduClient.createTable(tableInfo.getName(), tableInfo.getSchema(), tableInfo.getCreateTableOptions());
- } catch (
- KuduException e) {
+ kuduClient.createTable(
+ tableInfo.getName(), tableInfo.getSchema(), tableInfo.getCreateTableOptions());
+ } catch (KuduException e) {
throw new CatalogException("Could not create table " + tableInfo.getName(), e);
}
}
@Override
- public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) throws TableAlreadyExistException {
+ public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+ throws TableAlreadyExistException {
Map<String, String> tableProperties = table.getOptions();
TableSchema tableSchema = table.getSchema();
- Set<String> optionalProperties = new HashSet<>(Arrays.asList(KUDU_REPLICAS.key(),
- KUDU_HASH_PARTITION_NUMS.key(), KUDU_HASH_COLS.key()));
+ Set<String> optionalProperties =
+ new HashSet<>(
+ Arrays.asList(
+ KUDU_REPLICAS.key(),
+ KUDU_HASH_PARTITION_NUMS.key(),
+ KUDU_HASH_COLS.key()));
Set<String> requiredProperties = new HashSet<>();
if (!tableSchema.getPrimaryKey().isPresent()) {
@@ -228,19 +266,22 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
if (!tableProperties.keySet().containsAll(requiredProperties)) {
- throw new CatalogException("Missing required property. The following properties must be provided: " +
- requiredProperties.toString());
+ throw new CatalogException(
+ "Missing required property. The following properties must be provided: "
+ + requiredProperties.toString());
}
Set<String> permittedProperties = Sets.union(requiredProperties, optionalProperties);
if (!permittedProperties.containsAll(tableProperties.keySet())) {
- throw new CatalogException("Unpermitted properties were given. The following properties are allowed:" +
- permittedProperties.toString());
+ throw new CatalogException(
+ "Unpermitted properties were given. The following properties are allowed:"
+ + permittedProperties.toString());
}
String tableName = tablePath.getObjectName();
- KuduTableInfo tableInfo = KuduTableUtils.createTableInfo(tableName, tableSchema, tableProperties);
+ KuduTableInfo tableInfo =
+ KuduTableUtils.createTableInfo(tableName, tableSchema, tableProperties);
createTable(tableInfo, ignoreIfExists);
}
@@ -251,17 +292,20 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath) throws CatalogException {
+ public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath)
+ throws CatalogException {
return CatalogColumnStatistics.UNKNOWN;
}
@Override
- public CatalogTableStatistics getPartitionStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public CatalogTableStatistics getPartitionStatistics(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return CatalogTableStatistics.UNKNOWN;
}
@Override
- public CatalogColumnStatistics getPartitionColumnStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public CatalogColumnStatistics getPartitionColumnStatistics(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return CatalogColumnStatistics.UNKNOWN;
}
@@ -271,7 +315,8 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogDatabase getDatabase(String databaseName) throws DatabaseNotExistException, CatalogException {
+ public CatalogDatabase getDatabase(String databaseName)
+ throws DatabaseNotExistException, CatalogException {
if (databaseName.equals(getDefaultDatabase())) {
return new CatalogDatabaseImpl(new HashMap<>(), null);
} else {
@@ -295,17 +340,20 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public List<CatalogPartitionSpec> listPartitions(
+ ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
return Collections.emptyList();
}
@Override
- public List<CatalogPartitionSpec> listPartitionsByFilter(ObjectPath tablePath, List<Expression> filters) throws CatalogException {
+ public List<CatalogPartitionSpec> listPartitionsByFilter(
+ ObjectPath tablePath, List<Expression> filters) throws CatalogException {
return Collections.emptyList();
}
@Override
- public boolean partitionExists(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws CatalogException {
+ public boolean partitionExists(ObjectPath tablePath, CatalogPartitionSpec partitionSpec)
+ throws CatalogException {
return false;
}
@@ -315,7 +363,8 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
}
@Override
- public CatalogFunction getFunction(ObjectPath functionPath) throws FunctionNotExistException, CatalogException {
+ public CatalogFunction getFunction(ObjectPath functionPath)
+ throws FunctionNotExistException, CatalogException {
throw new FunctionNotExistException(getName(), functionPath);
}
@@ -323,5 +372,4 @@ public class KuduDynamicCatalog extends AbstractReadOnlyCatalog {
public boolean functionExists(ObjectPath functionPath) throws CatalogException {
return false;
}
-
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduLookupOptions.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduLookupOptions.java
index 9a2f23f..537a4c0 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduLookupOptions.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduLookupOptions.java
@@ -15,11 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.function.lookup;
-/**
- * Options for the Kudu lookup.
- */
+/** Options for the Kudu lookup. */
public class KuduLookupOptions {
private final long cacheMaxSize;
private final long cacheExpireMs;
@@ -39,17 +38,15 @@ public class KuduLookupOptions {
return cacheMaxSize;
}
-
public long getCacheExpireMs() {
return cacheExpireMs;
}
-
public int getMaxRetryTimes() {
return maxRetryTimes;
}
-
+ /** Builder for KuduLookupOptions. */
public static final class Builder {
private long cacheMaxSize;
private long cacheExpireMs;
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduRowDataLookupFunction.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduRowDataLookupFunction.java
index e26c080..b1198e7 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduRowDataLookupFunction.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/function/lookup/KuduRowDataLookupFunction.java
@@ -15,15 +15,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.function.lookup;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.compress.utils.Lists;
-import org.apache.commons.lang3.ArrayUtils;
import org.apache.flink.connectors.kudu.connector.KuduFilterInfo;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultConvertor;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowDataConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultConverter;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowDataConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduInputSplit;
import org.apache.flink.connectors.kudu.connector.reader.KuduReader;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
@@ -32,6 +30,10 @@ import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.functions.FunctionContext;
import org.apache.flink.table.functions.TableFunction;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.compress.utils.Lists;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.kudu.shaded.com.google.common.cache.Cache;
import org.apache.kudu.shaded.com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
@@ -43,9 +45,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
-/**
- * LookupFunction based on the RowData object type
- */
+/** LookupFunction based on the RowData object type. */
public class KuduRowDataLookupFunction extends TableFunction<RowData> {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(KuduRowDataLookupFunction.class);
@@ -57,15 +57,19 @@ public class KuduRowDataLookupFunction extends TableFunction<RowData> {
private final long cacheMaxSize;
private final long cacheExpireMs;
private final int maxRetryTimes;
- private final RowResultConvertor<RowData> convertor;
+ private final RowResultConverter<RowData> convertor;
private transient Cache<RowData, List<RowData>> cache;
private transient KuduReader<RowData> kuduReader;
- private KuduRowDataLookupFunction(String[] keyNames, KuduTableInfo tableInfo, KuduReaderConfig kuduReaderConfig,
- String[] projectedFields, KuduLookupOptions kuduLookupOptions) {
+ private KuduRowDataLookupFunction(
+ String[] keyNames,
+ KuduTableInfo tableInfo,
+ KuduReaderConfig kuduReaderConfig,
+ String[] projectedFields,
+ KuduLookupOptions kuduLookupOptions) {
this.tableInfo = tableInfo;
- this.convertor = new RowResultRowDataConvertor();
+ this.convertor = new RowResultRowDataConverter();
this.projectedFields = projectedFields;
this.keyNames = keyNames;
this.kuduReaderConfig = kuduReaderConfig;
@@ -106,7 +110,8 @@ public class KuduRowDataLookupFunction extends TableFunction<RowData> {
KuduInputSplit[] inputSplits = kuduReader.createInputSplits(1);
ArrayList<RowData> rows = new ArrayList<>();
for (KuduInputSplit inputSplit : inputSplits) {
- KuduReaderIterator<RowData> scanner = kuduReader.scanner(inputSplit.getScanToken());
+ KuduReaderIterator<RowData> scanner =
+ kuduReader.scanner(inputSplit.getScanToken());
// not use cache
if (cache == null) {
while (scanner.hasNext()) {
@@ -139,34 +144,32 @@ public class KuduRowDataLookupFunction extends TableFunction<RowData> {
}
}
- /**
- * build kuduFilterInfo
- *
- * @return kudu filters
- */
private List<KuduFilterInfo> buildKuduFilterInfo(Object... keyValS) {
List<KuduFilterInfo> kuduFilterInfos = Lists.newArrayList();
for (int i = 0; i < keyNames.length; i++) {
- KuduFilterInfo kuduFilterInfo = KuduFilterInfo.Builder.create(keyNames[i])
- .equalTo(keyValS[i]).build();
+ KuduFilterInfo kuduFilterInfo =
+ KuduFilterInfo.Builder.create(keyNames[i]).equalTo(keyValS[i]).build();
kuduFilterInfos.add(kuduFilterInfo);
}
return kuduFilterInfos;
}
-
@Override
public void open(FunctionContext context) {
try {
super.open(context);
- this.kuduReader = new KuduReader<>(this.tableInfo, this.kuduReaderConfig, this.convertor);
+ this.kuduReader =
+ new KuduReader<>(this.tableInfo, this.kuduReaderConfig, this.convertor);
// build kudu cache
- this.kuduReader.setTableProjections(ArrayUtils.isNotEmpty(projectedFields) ?
- Arrays.asList(projectedFields) : null);
- this.cache = this.cacheMaxSize == -1 || this.cacheExpireMs == -1 ? null : CacheBuilder.newBuilder()
- .expireAfterWrite(this.cacheExpireMs, TimeUnit.MILLISECONDS)
- .maximumSize(this.cacheMaxSize)
- .build();
+ this.kuduReader.setTableProjections(
+ ArrayUtils.isNotEmpty(projectedFields) ? Arrays.asList(projectedFields) : null);
+ this.cache =
+ this.cacheMaxSize == -1 || this.cacheExpireMs == -1
+ ? null
+ : CacheBuilder.newBuilder()
+ .expireAfterWrite(this.cacheExpireMs, TimeUnit.MILLISECONDS)
+ .maximumSize(this.cacheMaxSize)
+ .build();
} catch (Exception ioe) {
LOG.error("Exception while creating connection to Kudu.", ioe);
throw new RuntimeException("Cannot create connection to Kudu.", ioe);
@@ -191,6 +194,7 @@ public class KuduRowDataLookupFunction extends TableFunction<RowData> {
}
}
+ /** Builder for KuduRowDataLookupFunction. */
public static class Builder {
private KuduTableInfo tableInfo;
private KuduReaderConfig kuduReaderConfig;
@@ -228,8 +232,8 @@ public class KuduRowDataLookupFunction extends TableFunction<RowData> {
}
public KuduRowDataLookupFunction build() {
- return new KuduRowDataLookupFunction(keyNames, tableInfo, kuduReaderConfig, projectedFields,
- kuduLookupOptions);
+ return new KuduRowDataLookupFunction(
+ keyNames, tableInfo, kuduReaderConfig, projectedFields, kuduLookupOptions);
}
}
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTableUtils.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTableUtils.java
index cae36a3..0b99333 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTableUtils.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTableUtils.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.utils;
import org.apache.flink.api.java.tuple.Tuple2;
@@ -32,6 +33,7 @@ import org.apache.flink.table.types.DataType;
import org.apache.flink.table.types.logical.DecimalType;
import org.apache.flink.table.types.logical.TimestampType;
import org.apache.flink.table.utils.TableSchemaUtils;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.ColumnTypeAttributes;
import org.apache.kudu.Schema;
@@ -40,119 +42,153 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
+
import java.sql.Timestamp;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
-import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.*;
-
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_HASH_COLS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_HASH_PARTITION_NUMS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_PRIMARY_KEY_COLS;
+import static org.apache.flink.connectors.kudu.table.dynamic.KuduDynamicTableSourceSinkFactory.KUDU_REPLICAS;
+/** Kudu table utilities. */
public class KuduTableUtils {
private static final Logger LOG = LoggerFactory.getLogger(KuduTableUtils.class);
- public static KuduTableInfo createTableInfo(String tableName, TableSchema schema, Map<String, String> props) {
- // Since KUDU_HASH_COLS is a required property for table creation, we use it to infer whether to create table
- boolean createIfMissing = props.containsKey(KUDU_PRIMARY_KEY_COLS.key()) || schema.getPrimaryKey().isPresent();
+ public static KuduTableInfo createTableInfo(
+ String tableName, TableSchema schema, Map<String, String> props) {
+ // Since KUDU_HASH_COLS is a required property for table creation, we use it to infer
+ // whether to create table
+ boolean createIfMissing =
+ props.containsKey(KUDU_PRIMARY_KEY_COLS.key())
+ || schema.getPrimaryKey().isPresent();
KuduTableInfo tableInfo = KuduTableInfo.forTable(tableName);
if (createIfMissing) {
- List<Tuple2<String, DataType>> columns = getSchemaWithSqlTimestamp(schema)
- .getTableColumns()
- .stream()
- .map(tc -> Tuple2.of(tc.getName(), tc.getType()))
- .collect(Collectors.toList());
+ List<Tuple2<String, DataType>> columns =
+ getSchemaWithSqlTimestamp(schema).getTableColumns().stream()
+ .map(tc -> Tuple2.of(tc.getName(), tc.getType()))
+ .collect(Collectors.toList());
List<String> keyColumns = getPrimaryKeyColumns(props, schema);
ColumnSchemasFactory schemasFactory = () -> toKuduConnectorColumns(columns, keyColumns);
- int replicas = Optional.ofNullable(props.get(KUDU_REPLICAS.key())).map(Integer::parseInt).orElse(1);
+ int replicas =
+ Optional.ofNullable(props.get(KUDU_REPLICAS.key()))
+ .map(Integer::parseInt)
+ .orElse(1);
// if hash partitions nums not exists,default 3;
int hashPartitionNums =
- Optional.ofNullable(props.get(KUDU_HASH_PARTITION_NUMS.key())).map(Integer::parseInt).orElse(3);
- CreateTableOptionsFactory optionsFactory = () -> new CreateTableOptions()
- .setNumReplicas(replicas)
- .addHashPartitions(getHashColumns(props), hashPartitionNums);
+ Optional.ofNullable(props.get(KUDU_HASH_PARTITION_NUMS.key()))
+ .map(Integer::parseInt)
+ .orElse(3);
+ CreateTableOptionsFactory optionsFactory =
+ () ->
+ new CreateTableOptions()
+ .setNumReplicas(replicas)
+ .addHashPartitions(getHashColumns(props), hashPartitionNums);
tableInfo.createTableIfNotExists(schemasFactory, optionsFactory);
} else {
- LOG.debug("Property {} is missing, assuming the table is already created.", KUDU_HASH_COLS.key());
+ LOG.debug(
+ "Property {} is missing, assuming the table is already created.",
+ KUDU_HASH_COLS.key());
}
return tableInfo;
}
- public static List<ColumnSchema> toKuduConnectorColumns(List<Tuple2<String, DataType>> columns,
- Collection<String> keyColumns) {
+ public static List<ColumnSchema> toKuduConnectorColumns(
+ List<Tuple2<String, DataType>> columns, Collection<String> keyColumns) {
return columns.stream()
- .map(t -> {
- ColumnSchema.ColumnSchemaBuilder builder = new ColumnSchema
- .ColumnSchemaBuilder(t.f0, KuduTypeUtils.toKuduType(t.f1))
- .key(keyColumns.contains(t.f0))
- .nullable(!keyColumns.contains(t.f0) && t.f1.getLogicalType().isNullable());
+ .map(
+ t -> {
+ ColumnSchema.ColumnSchemaBuilder builder =
+ new ColumnSchema.ColumnSchemaBuilder(
+ t.f0, KuduTypeUtils.toKuduType(t.f1))
+ .key(keyColumns.contains(t.f0))
+ .nullable(
+ !keyColumns.contains(t.f0)
+ && t.f1.getLogicalType().isNullable());
if (t.f1.getLogicalType() instanceof DecimalType) {
DecimalType decimalType = ((DecimalType) t.f1.getLogicalType());
- builder.typeAttributes(new ColumnTypeAttributes.ColumnTypeAttributesBuilder()
- .precision(decimalType.getPrecision())
- .scale(decimalType.getScale())
- .build());
+ builder.typeAttributes(
+ new ColumnTypeAttributes.ColumnTypeAttributesBuilder()
+ .precision(decimalType.getPrecision())
+ .scale(decimalType.getScale())
+ .build());
}
return builder.build();
- }
- ).collect(Collectors.toList());
+ })
+ .collect(Collectors.toList());
}
public static TableSchema kuduToFlinkSchema(Schema schema) {
TableSchema.Builder builder = TableSchema.builder();
for (ColumnSchema column : schema.getColumns()) {
- DataType flinkType = KuduTypeUtils.toFlinkType(column.getType(), column.getTypeAttributes()).nullable();
+ DataType flinkType =
+ KuduTypeUtils.toFlinkType(column.getType(), column.getTypeAttributes())
+ .nullable();
builder.field(column.getName(), flinkType);
}
return builder.build();
}
- public static List<String> getPrimaryKeyColumns(Map<String, String> tableProperties, TableSchema tableSchema) {
- return tableProperties.containsKey(KUDU_PRIMARY_KEY_COLS.key()) ?
- Arrays.asList(tableProperties.get(KUDU_PRIMARY_KEY_COLS.key()).split(",")) :
- tableSchema.getPrimaryKey().get().getColumns();
+ public static List<String> getPrimaryKeyColumns(
+ Map<String, String> tableProperties, TableSchema tableSchema) {
+ return tableProperties.containsKey(KUDU_PRIMARY_KEY_COLS.key())
+ ? Arrays.asList(tableProperties.get(KUDU_PRIMARY_KEY_COLS.key()).split(","))
+ : tableSchema.getPrimaryKey().get().getColumns();
}
public static List<String> getHashColumns(Map<String, String> tableProperties) {
return Arrays.asList(tableProperties.get(KUDU_HASH_COLS.key()).split(","));
}
-
public static TableSchema getSchemaWithSqlTimestamp(TableSchema schema) {
TableSchema.Builder builder = new TableSchema.Builder();
- TableSchemaUtils.getPhysicalSchema(schema).getTableColumns().forEach(
- tableColumn -> {
- if (tableColumn.getType().getLogicalType() instanceof TimestampType) {
- builder.field(tableColumn.getName(), tableColumn.getType().bridgedTo(Timestamp.class));
- } else {
- builder.field(tableColumn.getName(), tableColumn.getType());
- }
- });
+ TableSchemaUtils.getPhysicalSchema(schema)
+ .getTableColumns()
+ .forEach(
+ tableColumn -> {
+ if (tableColumn.getType().getLogicalType() instanceof TimestampType) {
+ builder.field(
+ tableColumn.getName(),
+ tableColumn.getType().bridgedTo(Timestamp.class));
+ } else {
+ builder.field(tableColumn.getName(), tableColumn.getType());
+ }
+ });
return builder.build();
}
- /**
- * Converts Flink Expression to KuduFilterInfo.
- */
+ /** Converts Flink Expression to KuduFilterInfo. */
@Nullable
public static Optional<KuduFilterInfo> toKuduFilterInfo(Expression predicate) {
- LOG.debug("predicate summary: [{}], class: [{}], children: [{}]",
- predicate.asSummaryString(), predicate.getClass(), predicate.getChildren());
+ LOG.debug(
+ "predicate summary: [{}], class: [{}], children: [{}]",
+ predicate.asSummaryString(),
+ predicate.getClass(),
+ predicate.getChildren());
if (predicate instanceof CallExpression) {
CallExpression callExpression = (CallExpression) predicate;
FunctionDefinition functionDefinition = callExpression.getFunctionDefinition();
List<Expression> children = callExpression.getChildren();
if (children.size() == 1) {
return convertUnaryIsNullExpression(functionDefinition, children);
- } else if (children.size() == 2 &&
- !functionDefinition.equals(BuiltInFunctionDefinitions.OR)) {
+ } else if (children.size() == 2
+ && !functionDefinition.equals(BuiltInFunctionDefinitions.OR)) {
return convertBinaryComparison(functionDefinition, children);
- } else if (children.size() > 0 && functionDefinition.equals(BuiltInFunctionDefinitions.OR)) {
+ } else if (children.size() > 0
+ && functionDefinition.equals(BuiltInFunctionDefinitions.OR)) {
return convertIsInExpression(children);
}
}
@@ -190,12 +226,12 @@ public class KuduTableUtils {
FunctionDefinition functionDefinition, List<Expression> children) {
FieldReferenceExpression fieldReferenceExpression;
ValueLiteralExpression valueLiteralExpression;
- if (isFieldReferenceExpression(children.get(0)) &&
- isValueLiteralExpression(children.get(1))) {
+ if (isFieldReferenceExpression(children.get(0))
+ && isValueLiteralExpression(children.get(1))) {
fieldReferenceExpression = (FieldReferenceExpression) children.get(0);
valueLiteralExpression = (ValueLiteralExpression) children.get(1);
- } else if (isValueLiteralExpression(children.get(0)) &&
- isFieldReferenceExpression(children.get(1))) {
+ } else if (isValueLiteralExpression(children.get(0))
+ && isFieldReferenceExpression(children.get(1))) {
fieldReferenceExpression = (FieldReferenceExpression) children.get(1);
valueLiteralExpression = (ValueLiteralExpression) children.get(0);
} else {
@@ -235,9 +271,10 @@ public class KuduTableUtils {
List<Expression> subChildren = callExpression.getChildren();
FieldReferenceExpression fieldReferenceExpression;
ValueLiteralExpression valueLiteralExpression;
- if (functionDefinition.equals(BuiltInFunctionDefinitions.EQUALS) &&
- subChildren.size() == 2 && isFieldReferenceExpression(subChildren.get(0)) &&
- isValueLiteralExpression(subChildren.get(1))) {
+ if (functionDefinition.equals(BuiltInFunctionDefinitions.EQUALS)
+ && subChildren.size() == 2
+ && isFieldReferenceExpression(subChildren.get(0))
+ && isValueLiteralExpression(subChildren.get(1))) {
fieldReferenceExpression = (FieldReferenceExpression) subChildren.get(0);
valueLiteralExpression = (ValueLiteralExpression) subChildren.get(1);
String fieldName = fieldReferenceExpression.getName();
@@ -246,8 +283,8 @@ public class KuduTableUtils {
} else {
columnName = fieldName;
}
- Object value = extractValueLiteral(fieldReferenceExpression,
- valueLiteralExpression);
+ Object value =
+ extractValueLiteral(fieldReferenceExpression, valueLiteralExpression);
if (value == null) {
return Optional.empty();
}
@@ -263,8 +300,9 @@ public class KuduTableUtils {
return Optional.of(builder.isIn(values).build());
}
- private static Object extractValueLiteral(FieldReferenceExpression fieldReferenceExpression,
- ValueLiteralExpression valueLiteralExpression) {
+ private static Object extractValueLiteral(
+ FieldReferenceExpression fieldReferenceExpression,
+ ValueLiteralExpression valueLiteralExpression) {
DataType fieldType = fieldReferenceExpression.getOutputDataType();
return valueLiteralExpression.getValueAs(fieldType.getConversionClass()).orElse(null);
}
diff --git a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTypeUtils.java b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTypeUtils.java
index 15f7be7..3f18bb9 100644
--- a/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTypeUtils.java
+++ b/flink-connector-kudu/src/main/java/org/apache/flink/connectors/kudu/table/utils/KuduTypeUtils.java
@@ -20,8 +20,20 @@ package org.apache.flink.connectors.kudu.table.utils;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.types.AtomicDataType;
import org.apache.flink.table.types.DataType;
-import org.apache.flink.table.types.logical.*;
+import org.apache.flink.table.types.logical.BigIntType;
+import org.apache.flink.table.types.logical.BooleanType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.DoubleType;
+import org.apache.flink.table.types.logical.FloatType;
+import org.apache.flink.table.types.logical.IntType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.SmallIntType;
+import org.apache.flink.table.types.logical.TimestampType;
+import org.apache.flink.table.types.logical.TinyIntType;
+import org.apache.flink.table.types.logical.VarBinaryType;
+import org.apache.flink.table.types.logical.VarCharType;
import org.apache.flink.table.types.logical.utils.LogicalTypeDefaultVisitor;
+
import org.apache.kudu.ColumnTypeAttributes;
import org.apache.kudu.Type;
@@ -29,6 +41,7 @@ import java.sql.Timestamp;
import static org.apache.flink.util.Preconditions.checkNotNull;
+/** Kudu type utilities. */
public class KuduTypeUtils {
public static DataType toFlinkType(Type type, ColumnTypeAttributes typeAttributes) {
@@ -133,8 +146,9 @@ public class KuduTypeUtils {
@Override
protected Type defaultMethod(LogicalType logicalType) {
throw new UnsupportedOperationException(
- String.format("Flink doesn't support converting type %s to Kudu type yet.", dataType.toString()));
+ String.format(
+ "Flink doesn't support converting type %s to Kudu type yet.",
+ dataType.toString()));
}
-
}
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfoTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfoTest.java
index a6c2ff7..731af29 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfoTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduFilterInfoTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector;
import org.apache.flink.table.data.binary.BinaryStringData;
@@ -24,18 +25,19 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+/** Tests for {@link KuduFilterInfo}. */
public class KuduFilterInfoTest {
@Test
void testKuduFilterInfoWithBinaryStringData() {
String filterValue = "someValue";
- KuduFilterInfo kuduFilterInfo = KuduFilterInfo.Builder.create("col")
- .equalTo(BinaryStringData.fromString(filterValue))
- .build();
+ KuduFilterInfo kuduFilterInfo =
+ KuduFilterInfo.Builder.create("col")
+ .equalTo(BinaryStringData.fromString(filterValue))
+ .build();
ColumnSchema colSchema = new ColumnSchema.ColumnSchemaBuilder("col", Type.STRING).build();
assertDoesNotThrow(() -> kuduFilterInfo.toPredicate(colSchema));
}
-
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduTestBase.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduTestBase.java
index ac4db4c..b6772e6 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduTestBase.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/connector/KuduTestBase.java
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.connector;
import org.apache.flink.api.java.tuple.Tuple5;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowConvertor;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowDataConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowConverter;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowDataConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduInputSplit;
import org.apache.flink.connectors.kudu.connector.reader.KuduReader;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
@@ -33,10 +34,15 @@ import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.table.data.StringData;
import org.apache.flink.types.Row;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.Type;
-import org.apache.kudu.client.*;
+import org.apache.kudu.client.CreateTableOptions;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduScanner;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.client.RowResult;
import org.apache.kudu.shaded.com.google.common.collect.Lists;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
@@ -57,6 +63,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+/** Base class for integration tests. */
public class KuduTestBase {
private static final String DOCKER_IMAGE = "apache/kudu:1.13.0";
@@ -64,12 +71,13 @@ public class KuduTestBase {
private static final Integer KUDU_TSERVER_PORT = 7050;
private static final Integer NUMBER_OF_REPLICA = 3;
private static final Object[][] booksTableData = {
- {1001, "Java for dummies", "Tan Ah Teck", 11.11, 11},
- {1002, "More Java for dummies", "Tan Ah Teck", 22.22, 22},
- {1003, "More Java for more dummies", "Mohammad Ali", 33.33, 33},
- {1004, "A Cup of Java", "Kumar", 44.44, 44},
- {1005, "A Teaspoon of Java", "Kevin Jones", 55.55, 55}};
- public static String[] columns = new String[]{"id", "title", "author", "price", "quantity"};
+ {1001, "Java for dummies", "Tan Ah Teck", 11.11, 11},
+ {1002, "More Java for dummies", "Tan Ah Teck", 22.22, 22},
+ {1003, "More Java for more dummies", "Mohammad Ali", 33.33, 33},
+ {1004, "A Cup of Java", "Kumar", 44.44, 44},
+ {1005, "A Teaspoon of Java", "Kevin Jones", 55.55, 55}
+ };
+ public static String[] columns = new String[] {"id", "title", "author", "price", "quantity"};
private static GenericContainer<?> master;
private static List<GenericContainer<?>> tServers;
private static HostAndPort masterAddress;
@@ -80,25 +88,31 @@ public class KuduTestBase {
Network network = Network.newNetwork();
ImmutableList.Builder<GenericContainer<?>> tServersBuilder = ImmutableList.builder();
- master = new GenericContainer<>(DOCKER_IMAGE)
- .withExposedPorts(KUDU_MASTER_PORT, 8051)
- .withCommand("master")
- .withNetwork(network)
- .withNetworkAliases("kudu-master");
+ master =
+ new GenericContainer<>(DOCKER_IMAGE)
+ .withExposedPorts(KUDU_MASTER_PORT, 8051)
+ .withCommand("master")
+ .withNetwork(network)
+ .withNetworkAliases("kudu-master");
master.start();
- masterAddress = HostAndPort.fromParts(master.getHost(), master.getMappedPort(KUDU_MASTER_PORT));
+ masterAddress =
+ HostAndPort.fromParts(master.getHost(), master.getMappedPort(KUDU_MASTER_PORT));
for (int instance = 1; instance <= NUMBER_OF_REPLICA; instance++) {
String instanceName = "kudu-tserver-" + instance;
- GenericContainer<?> tableServer = new GenericContainer<>(DOCKER_IMAGE)
- .withExposedPorts(KUDU_TSERVER_PORT)
- .withCommand("tserver")
- .withEnv("KUDU_MASTERS", "kudu-master:" + KUDU_MASTER_PORT)
- .withEnv("TSERVER_ARGS", "--fs_wal_dir=/var/lib/kudu/tserver --logtostderr "
- +" --use_hybrid_clock=false --rpc_advertised_addresses=" + instanceName)
- .withNetwork(network)
- .withNetworkAliases(instanceName)
- .dependsOn(master);
+ GenericContainer<?> tableServer =
+ new GenericContainer<>(DOCKER_IMAGE)
+ .withExposedPorts(KUDU_TSERVER_PORT)
+ .withCommand("tserver")
+ .withEnv("KUDU_MASTERS", "kudu-master:" + KUDU_MASTER_PORT)
+ .withEnv(
+ "TSERVER_ARGS",
+ "--fs_wal_dir=/var/lib/kudu/tserver --logtostderr "
+ + " --use_hybrid_clock=false --rpc_advertised_addresses="
+ + instanceName)
+ .withNetwork(network)
+ .withNetworkAliases(instanceName)
+ .dependsOn(master);
tableServer.start();
tServersBuilder.add(tableServer);
}
@@ -123,21 +137,35 @@ public class KuduTestBase {
KuduTableInfo tableInfo = KuduTableInfo.forTable(tableName);
if (createIfNotExist) {
- ColumnSchemasFactory schemasFactory = () -> {
- List<ColumnSchema> schemas = new ArrayList<>();
- schemas.add(new ColumnSchema.ColumnSchemaBuilder("id", Type.INT32).key(true).build());
- schemas.add(new ColumnSchema.ColumnSchemaBuilder("title", Type.STRING).build());
- schemas.add(new ColumnSchema.ColumnSchemaBuilder("author", Type.STRING).build());
- schemas.add(new ColumnSchema.ColumnSchemaBuilder("price", Type.DOUBLE).nullable(true).build());
- schemas.add(new ColumnSchema.ColumnSchemaBuilder("quantity", Type.INT32).nullable(true).build());
- return schemas;
- };
+ ColumnSchemasFactory schemasFactory =
+ () -> {
+ List<ColumnSchema> schemas = new ArrayList<>();
+ schemas.add(
+ new ColumnSchema.ColumnSchemaBuilder("id", Type.INT32)
+ .key(true)
+ .build());
+ schemas.add(
+ new ColumnSchema.ColumnSchemaBuilder("title", Type.STRING).build());
+ schemas.add(
+ new ColumnSchema.ColumnSchemaBuilder("author", Type.STRING)
+ .build());
+ schemas.add(
+ new ColumnSchema.ColumnSchemaBuilder("price", Type.DOUBLE)
+ .nullable(true)
+ .build());
+ schemas.add(
+ new ColumnSchema.ColumnSchemaBuilder("quantity", Type.INT32)
+ .nullable(true)
+ .build());
+ return schemas;
+ };
tableInfo.createTableIfNotExists(
schemasFactory,
- () -> new CreateTableOptions()
- .setNumReplicas(1)
- .addHashPartitions(Lists.newArrayList("id"), 2));
+ () ->
+ new CreateTableOptions()
+ .setNumReplicas(1)
+ .addHashPartitions(Lists.newArrayList("id"), 2));
}
return tableInfo;
@@ -145,33 +173,37 @@ public class KuduTestBase {
public static List<Tuple5<Integer, String, String, Double, Integer>> booksDataTuple() {
return Arrays.stream(booksTableData)
- .map(row -> {
- Integer rowId = (Integer) row[0];
- if (rowId % 2 == 1) {
- Tuple5<Integer, String, String, Double, Integer> values =
- Tuple5.of((Integer) row[0],
- (String) row[1],
- (String) row[2],
- (Double) row[3],
- (Integer) row[4]);
- return values;
- } else {
- Tuple5<Integer, String, String, Double, Integer> values =
- Tuple5.of((Integer) row[0],
- (String) row[1],
- (String) row[2],
- null, null);
- return values;
- }
- })
+ .map(
+ row -> {
+ Integer rowId = (Integer) row[0];
+ if (rowId % 2 == 1) {
+ Tuple5<Integer, String, String, Double, Integer> values =
+ Tuple5.of(
+ (Integer) row[0],
+ (String) row[1],
+ (String) row[2],
+ (Double) row[3],
+ (Integer) row[4]);
+ return values;
+ } else {
+ Tuple5<Integer, String, String, Double, Integer> values =
+ Tuple5.of(
+ (Integer) row[0],
+ (String) row[1],
+ (String) row[2],
+ null,
+ null);
+ return values;
+ }
+ })
.collect(Collectors.toList());
}
- public static TableSchema booksTableSchema(){
+ public static TableSchema booksTableSchema() {
return TableSchema.builder()
.field("id", DataTypes.INT())
.field("title", DataTypes.STRING())
- .field( "author", DataTypes.STRING())
+ .field("author", DataTypes.STRING())
.field("price", DataTypes.DOUBLE())
.field("quantity", DataTypes.INT())
.build();
@@ -179,57 +211,62 @@ public class KuduTestBase {
public static List<RowData> booksRowData() {
return Arrays.stream(booksTableData)
- .map(row -> {
- Integer rowId = (Integer) row[0];
- if (rowId % 2 == 1) {
- GenericRowData values = new GenericRowData(5);
- values.setField(0, row[0]);
- values.setField(1, StringData.fromString(row[1].toString()));
- values.setField(2, StringData.fromString(row[2].toString()));
- values.setField(3, row[3]);
- values.setField(4, row[4]);
- return values;
- } else {
- GenericRowData values = new GenericRowData(5);
- values.setField(0, row[0]);
- values.setField(1, StringData.fromString(row[1].toString()));
- values.setField(2, StringData.fromString(row[2].toString()));
- return values;
- }
- })
+ .map(
+ row -> {
+ Integer rowId = (Integer) row[0];
+ if (rowId % 2 == 1) {
+ GenericRowData values = new GenericRowData(5);
+ values.setField(0, row[0]);
+ values.setField(1, StringData.fromString(row[1].toString()));
+ values.setField(2, StringData.fromString(row[2].toString()));
+ values.setField(3, row[3]);
+ values.setField(4, row[4]);
+ return values;
+ } else {
+ GenericRowData values = new GenericRowData(5);
+ values.setField(0, row[0]);
+ values.setField(1, StringData.fromString(row[1].toString()));
+ values.setField(2, StringData.fromString(row[2].toString()));
+ return values;
+ }
+ })
.collect(Collectors.toList());
}
public static List<Row> booksDataRow() {
return Arrays.stream(booksTableData)
- .map(row -> {
- Integer rowId = (Integer) row[0];
- if (rowId % 2 == 1) {
- Row values = new Row(5);
- values.setField(0, row[0]);
- values.setField(1, row[1]);
- values.setField(2, row[2]);
- values.setField(3, row[3]);
- values.setField(4, row[4]);
- return values;
- } else {
- Row values = new Row(5);
- values.setField(0, row[0]);
- values.setField(1, row[1]);
- values.setField(2, row[2]);
- return values;
- }
- })
+ .map(
+ row -> {
+ Integer rowId = (Integer) row[0];
+ if (rowId % 2 == 1) {
+ Row values = new Row(5);
+ values.setField(0, row[0]);
+ values.setField(1, row[1]);
+ values.setField(2, row[2]);
+ values.setField(3, row[3]);
+ values.setField(4, row[4]);
+ return values;
+ } else {
+ Row values = new Row(5);
+ values.setField(0, row[0]);
+ values.setField(1, row[1]);
+ values.setField(2, row[2]);
+ return values;
+ }
+ })
.collect(Collectors.toList());
}
public static List<BookInfo> booksDataPojo() {
- return Arrays.stream(booksTableData).map(row -> new BookInfo(
- (int) row[0],
- (String) row[1],
- (String) row[2],
- (Double) row[3],
- (int) row[4]))
+ return Arrays.stream(booksTableData)
+ .map(
+ row ->
+ new BookInfo(
+ (int) row[0],
+ (String) row[1],
+ (String) row[2],
+ (Double) row[3],
+ (int) row[4]))
.collect(Collectors.toList());
}
@@ -244,16 +281,23 @@ public class KuduTestBase {
protected void setUpDatabase(KuduTableInfo tableInfo) {
try {
String masterAddresses = getMasterAddress();
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- KuduWriter kuduWriter = new KuduWriter(tableInfo, writerConfig, new RowOperationMapper(columns,
- AbstractSingleOperationMapper.KuduOperation.INSERT));
- booksDataRow().forEach(row -> {
- try {
- kuduWriter.write(row);
- } catch (Exception e) {
- e.printStackTrace();
- }
- });
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ KuduWriter kuduWriter =
+ new KuduWriter(
+ tableInfo,
+ writerConfig,
+ new RowOperationMapper(
+ columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ booksDataRow()
+ .forEach(
+ row -> {
+ try {
+ kuduWriter.write(row);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
kuduWriter.close();
} catch (Exception e) {
Assertions.fail(e.getMessage());
@@ -263,9 +307,14 @@ public class KuduTestBase {
protected void cleanDatabase(KuduTableInfo tableInfo) {
try {
String masterAddresses = getMasterAddress();
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- KuduWriter kuduWriter = new KuduWriter(tableInfo, writerConfig, new RowOperationMapper(columns,
- AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ KuduWriter kuduWriter =
+ new KuduWriter(
+ tableInfo,
+ writerConfig,
+ new RowOperationMapper(
+ columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
kuduWriter.deleteTable();
kuduWriter.close();
} catch (Exception e) {
@@ -275,8 +324,10 @@ public class KuduTestBase {
protected List<Row> readRows(KuduTableInfo tableInfo) throws Exception {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- KuduReader<Row> reader = new KuduReader<>(tableInfo, readerConfig, new RowResultRowConvertor());
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ KuduReader<Row> reader =
+ new KuduReader<>(tableInfo, readerConfig, new RowResultRowConverter());
KuduInputSplit[] splits = reader.createInputSplits(1);
List<Row> rows = new ArrayList<>();
@@ -296,8 +347,10 @@ public class KuduTestBase {
protected List<RowData> readRowDatas(KuduTableInfo tableInfo) throws Exception {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- KuduReader<RowData> reader = new KuduReader<>(tableInfo, readerConfig, new RowResultRowDataConvertor());
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ KuduReader<RowData> reader =
+ new KuduReader<>(tableInfo, readerConfig, new RowResultRowDataConverter());
KuduInputSplit[] splits = reader.createInputSplits(1);
List<RowData> rows = new ArrayList<>();
@@ -347,13 +400,13 @@ public class KuduTestBase {
assertEquals("s", rows.get(0).getString("second"));
}
+ /** Dummy data class. */
public static class BookInfo {
public int id, quantity;
public String title, author;
public Double price;
- public BookInfo() {
- }
+ public BookInfo() {}
public BookInfo(int id, String title, String author, Double price, int quantity) {
this.id = id;
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduOutputFormatTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduOutputFormatTest.java
index f53b7c5..53b285a 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduOutputFormatTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduOutputFormatTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -22,6 +23,7 @@ import org.apache.flink.connectors.kudu.connector.writer.AbstractSingleOperation
import org.apache.flink.connectors.kudu.connector.writer.KuduWriterConfig;
import org.apache.flink.connectors.kudu.connector.writer.RowOperationMapper;
import org.apache.flink.types.Row;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -33,22 +35,32 @@ class KuduOutputFormatTest extends KuduTestBase {
@Test
void testInvalidKuduMaster() {
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), false);
- Assertions.assertThrows(NullPointerException.class, () -> new KuduOutputFormat<>(null, tableInfo, null));
+ Assertions.assertThrows(
+ NullPointerException.class, () -> new KuduOutputFormat<>(null, tableInfo, null));
}
@Test
void testInvalidTableInfo() {
String masterAddresses = getMasterAddress();
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- Assertions.assertThrows(NullPointerException.class, () -> new KuduOutputFormat<>(writerConfig, null, null));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ Assertions.assertThrows(
+ NullPointerException.class, () -> new KuduOutputFormat<>(writerConfig, null, null));
}
@Test
void testNotTableExist() {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), false);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- KuduOutputFormat<Row> outputFormat = new KuduOutputFormat<>(writerConfig, tableInfo, new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ KuduOutputFormat<Row> outputFormat =
+ new KuduOutputFormat<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT));
Assertions.assertThrows(RuntimeException.class, () -> outputFormat.open(0, 1));
}
@@ -57,11 +69,15 @@ class KuduOutputFormatTest extends KuduTestBase {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), true);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder
- .setMasters(masterAddresses)
- .setStrongConsistency()
- .build();
- KuduOutputFormat<Row> outputFormat = new KuduOutputFormat<>(writerConfig, tableInfo, new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).setStrongConsistency().build();
+ KuduOutputFormat<Row> outputFormat =
+ new KuduOutputFormat<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT));
outputFormat.open(0, 1);
@@ -82,11 +98,17 @@ class KuduOutputFormatTest extends KuduTestBase {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), true);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder
- .setMasters(masterAddresses)
- .setEventualConsistency()
- .build();
- KuduOutputFormat<Row> outputFormat = new KuduOutputFormat<>(writerConfig, tableInfo, new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses)
+ .setEventualConsistency()
+ .build();
+ KuduOutputFormat<Row> outputFormat =
+ new KuduOutputFormat<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT));
outputFormat.open(0, 1);
@@ -105,5 +127,4 @@ class KuduOutputFormatTest extends KuduTestBase {
cleanDatabase(tableInfo);
}
-
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormatTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormatTest.java
index aa391fc..f5996f8 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormatTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowDataInputFormatTest.java
@@ -14,17 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowConvertor;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowDataConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowConverter;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowDataConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduInputSplit;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.table.data.GenericRowData;
import org.apache.flink.table.data.RowData;
import org.apache.flink.types.Row;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -37,16 +39,21 @@ class KuduRowDataInputFormatTest extends KuduTestBase {
@Test
void testInvalidKuduMaster() {
KuduTableInfo tableInfo = booksTableInfo("books", false);
- Assertions.assertThrows(NullPointerException.class, () -> new KuduRowDataInputFormat(null,
- new RowResultRowDataConvertor(), tableInfo));
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () -> new KuduRowDataInputFormat(null, new RowResultRowDataConverter(), tableInfo));
}
@Test
void testInvalidTableInfo() {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- Assertions.assertThrows(NullPointerException.class, () -> new KuduRowDataInputFormat(readerConfig,
- new RowResultRowDataConvertor(), null));
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () ->
+ new KuduRowDataInputFormat(
+ readerConfig, new RowResultRowDataConverter(), null));
}
@Test
@@ -75,11 +82,18 @@ class KuduRowDataInputFormatTest extends KuduTestBase {
cleanDatabase(tableInfo);
}
- private List<RowData> readRowDatas(KuduTableInfo tableInfo, String... fieldProjection) throws Exception {
+ private List<RowData> readRowDatas(KuduTableInfo tableInfo, String... fieldProjection)
+ throws Exception {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- KuduRowDataInputFormat inputFormat = new KuduRowDataInputFormat(readerConfig, new RowResultRowDataConvertor(),
- tableInfo, new ArrayList<>(), fieldProjection == null ? null : Arrays.asList(fieldProjection));
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ KuduRowDataInputFormat inputFormat =
+ new KuduRowDataInputFormat(
+ readerConfig,
+ new RowResultRowDataConverter(),
+ tableInfo,
+ new ArrayList<>(),
+ fieldProjection == null ? null : Arrays.asList(fieldProjection));
KuduInputSplit[] splits = inputFormat.createInputSplits(1);
List<RowData> rows = new ArrayList<>();
@@ -97,11 +111,18 @@ class KuduRowDataInputFormatTest extends KuduTestBase {
return rows;
}
- private List<Row> readRows(KuduTableInfo tableInfo, String... fieldProjection) throws Exception {
+ private List<Row> readRows(KuduTableInfo tableInfo, String... fieldProjection)
+ throws Exception {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- KuduRowInputFormat inputFormat = new KuduRowInputFormat(readerConfig, new RowResultRowConvertor(), tableInfo,
- new ArrayList<>(), fieldProjection == null ? null : Arrays.asList(fieldProjection));
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ KuduRowInputFormat inputFormat =
+ new KuduRowInputFormat(
+ readerConfig,
+ new RowResultRowConverter(),
+ tableInfo,
+ new ArrayList<>(),
+ fieldProjection == null ? null : Arrays.asList(fieldProjection));
KuduInputSplit[] splits = inputFormat.createInputSplits(1);
List<Row> rows = new ArrayList<>();
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormatTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormatTest.java
index cb413a5..3bb0b3c 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormatTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/format/KuduRowInputFormatTest.java
@@ -14,14 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.format;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
-import org.apache.flink.connectors.kudu.connector.convertor.RowResultRowConvertor;
+import org.apache.flink.connectors.kudu.connector.converter.RowResultRowConverter;
import org.apache.flink.connectors.kudu.connector.reader.KuduInputSplit;
import org.apache.flink.connectors.kudu.connector.reader.KuduReaderConfig;
import org.apache.flink.types.Row;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -34,16 +36,19 @@ class KuduRowInputFormatTest extends KuduTestBase {
@Test
void testInvalidKuduMaster() {
KuduTableInfo tableInfo = booksTableInfo("books", false);
- Assertions.assertThrows(NullPointerException.class, () -> new KuduRowInputFormat(null,
- new RowResultRowConvertor(), tableInfo));
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () -> new KuduRowInputFormat(null, new RowResultRowConverter(), tableInfo));
}
@Test
void testInvalidTableInfo() {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- Assertions.assertThrows(NullPointerException.class, () -> new KuduRowInputFormat(readerConfig,
- new RowResultRowConvertor(), null));
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () -> new KuduRowInputFormat(readerConfig, new RowResultRowConverter(), null));
}
@Test
@@ -72,11 +77,18 @@ class KuduRowInputFormatTest extends KuduTestBase {
cleanDatabase(tableInfo);
}
- private List<Row> readRows(KuduTableInfo tableInfo, String... fieldProjection) throws Exception {
+ private List<Row> readRows(KuduTableInfo tableInfo, String... fieldProjection)
+ throws Exception {
String masterAddresses = getMasterAddress();
- KuduReaderConfig readerConfig = KuduReaderConfig.Builder.setMasters(masterAddresses).build();
- KuduRowInputFormat inputFormat = new KuduRowInputFormat(readerConfig, new RowResultRowConvertor(), tableInfo,
- new ArrayList<>(), fieldProjection == null ? null : Arrays.asList(fieldProjection));
+ KuduReaderConfig readerConfig =
+ KuduReaderConfig.Builder.setMasters(masterAddresses).build();
+ KuduRowInputFormat inputFormat =
+ new KuduRowInputFormat(
+ readerConfig,
+ new RowResultRowConverter(),
+ tableInfo,
+ new ArrayList<>(),
+ fieldProjection == null ? null : Arrays.asList(fieldProjection));
KuduInputSplit[] splits = inputFormat.createInputSplits(1);
List<Row> rows = new ArrayList<>();
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/streaming/KuduSinkTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/streaming/KuduSinkTest.java
index 1764608..b8a30e5 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/streaming/KuduSinkTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/streaming/KuduSinkTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.streaming;
import org.apache.flink.configuration.Configuration;
@@ -24,6 +25,7 @@ import org.apache.flink.connectors.kudu.connector.writer.KuduWriterConfig;
import org.apache.flink.connectors.kudu.connector.writer.RowOperationMapper;
import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
import org.apache.flink.types.Row;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Type;
import org.apache.kudu.client.CreateTableOptions;
@@ -38,10 +40,11 @@ import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.UUID;
+/** Tests for {@link KuduSink}. */
public class KuduSinkTest extends KuduTestBase {
private static final Logger LOG = LoggerFactory.getLogger(KuduSinkTest.class);
- private static final String[] columns = new String[]{"id", "uuid"};
+ private static final String[] columns = new String[] {"id", "uuid"};
private static StreamingRuntimeContext context;
@BeforeAll
@@ -53,22 +56,45 @@ public class KuduSinkTest extends KuduTestBase {
@Test
void testInvalidKuduMaster() {
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), false);
- Assertions.assertThrows(NullPointerException.class, () -> new KuduSink<>(null, tableInfo, new RowOperationMapper(columns, AbstractSingleOperationMapper.KuduOperation.INSERT)));
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () ->
+ new KuduSink<>(
+ null,
+ tableInfo,
+ new RowOperationMapper(
+ columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT)));
}
@Test
void testInvalidTableInfo() {
String masterAddresses = getMasterAddress();
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- Assertions.assertThrows(NullPointerException.class, () -> new KuduSink<>(writerConfig, null, new RowOperationMapper(columns, AbstractSingleOperationMapper.KuduOperation.INSERT)));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ Assertions.assertThrows(
+ NullPointerException.class,
+ () ->
+ new KuduSink<>(
+ writerConfig,
+ null,
+ new RowOperationMapper(
+ columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT)));
}
@Test
void testNotTableExist() {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), false);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(masterAddresses).build();
- KuduSink<Row> sink = new KuduSink<>(writerConfig, tableInfo, new RowOperationMapper(columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).build();
+ KuduSink<Row> sink =
+ new KuduSink<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
sink.setRuntimeContext(context);
Assertions.assertThrows(RuntimeException.class, () -> sink.open(new Configuration()));
@@ -79,11 +105,15 @@ public class KuduSinkTest extends KuduTestBase {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), true);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder
- .setMasters(masterAddresses)
- .setStrongConsistency()
- .build();
- KuduSink<Row> sink = new KuduSink<>(writerConfig, tableInfo, new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses).setStrongConsistency().build();
+ KuduSink<Row> sink =
+ new KuduSink<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT));
sink.setRuntimeContext(context);
sink.open(new Configuration());
@@ -103,11 +133,17 @@ public class KuduSinkTest extends KuduTestBase {
String masterAddresses = getMasterAddress();
KuduTableInfo tableInfo = booksTableInfo(UUID.randomUUID().toString(), true);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder
- .setMasters(masterAddresses)
- .setEventualConsistency()
- .build();
- KuduSink<Row> sink = new KuduSink<>(writerConfig, tableInfo, new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses)
+ .setEventualConsistency()
+ .build();
+ KuduSink<Row> sink =
+ new KuduSink<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT));
sink.setRuntimeContext(context);
sink.open(new Configuration());
@@ -130,28 +166,33 @@ public class KuduSinkTest extends KuduTestBase {
void testSpeed() throws Exception {
String masterAddresses = getMasterAddress();
- KuduTableInfo tableInfo = KuduTableInfo
- .forTable("test_speed")
- .createTableIfNotExists(
- () ->
- Lists.newArrayList(
- new ColumnSchema
- .ColumnSchemaBuilder("id", Type.INT32)
- .key(true)
- .build(),
- new ColumnSchema
- .ColumnSchemaBuilder("uuid", Type.STRING)
- .build()
- ),
- () -> new CreateTableOptions()
- .setNumReplicas(3)
- .addHashPartitions(Lists.newArrayList("id"), 6));
-
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder
- .setMasters(masterAddresses)
- .setEventualConsistency()
- .build();
- KuduSink<Row> sink = new KuduSink<>(writerConfig, tableInfo, new RowOperationMapper(columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
+ KuduTableInfo tableInfo =
+ KuduTableInfo.forTable("test_speed")
+ .createTableIfNotExists(
+ () ->
+ Lists.newArrayList(
+ new ColumnSchema.ColumnSchemaBuilder(
+ "id", Type.INT32)
+ .key(true)
+ .build(),
+ new ColumnSchema.ColumnSchemaBuilder(
+ "uuid", Type.STRING)
+ .build()),
+ () ->
+ new CreateTableOptions()
+ .setNumReplicas(3)
+ .addHashPartitions(Lists.newArrayList("id"), 6));
+
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(masterAddresses)
+ .setEventualConsistency()
+ .build();
+ KuduSink<Row> sink =
+ new KuduSink<>(
+ writerConfig,
+ tableInfo,
+ new RowOperationMapper(
+ columns, AbstractSingleOperationMapper.KuduOperation.INSERT));
sink.setRuntimeContext(context);
sink.open(new Configuration());
@@ -172,5 +213,4 @@ public class KuduSinkTest extends KuduTestBase {
List<Row> rows = readRows(tableInfo);
Assertions.assertEquals(totalRecords, rows.size());
}
-
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduCatalogTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduCatalogTest.java
index d403d9c..fe6e15d 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduCatalogTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduCatalogTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.api.common.typeinfo.TypeHint;
@@ -34,6 +35,7 @@ import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.catalog.CatalogTable;
import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.types.Row;
+
import org.apache.kudu.ColumnSchema;
import org.apache.kudu.Schema;
import org.apache.kudu.Type;
@@ -54,8 +56,11 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertFalse;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+/** Tests for {@link KuduCatalog}. */
public class KuduCatalogTest extends KuduTestBase {
private KuduCatalog catalog;
@@ -72,7 +77,8 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testCreateAlterDrop() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable1 (`first` STRING, `second` String) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable1 (`first` STRING, `second` String) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
tableEnv.executeSql("INSERT INTO TestTable1 VALUES ('f', 's')")
.getJobClient()
.get()
@@ -80,10 +86,10 @@ public class KuduCatalogTest extends KuduTestBase {
.get(1, TimeUnit.MINUTES);
// Add this once Primary key support has been enabled
- // tableEnv.sqlUpdate("CREATE TABLE TestTable2 (`first` STRING, `second` String, PRIMARY KEY(`first`)) WITH ('kudu.hash-columns' = 'first')");
+ // tableEnv.sqlUpdate("CREATE TABLE TestTable2 (`first` STRING, `second` String, PRIMARY
+ // KEY(`first`)) WITH ('kudu.hash-columns' = 'first')");
// tableEnv.sqlUpdate("INSERT INTO TestTable2 VALUES ('f', 's')");
-
validateSingleKey("TestTable1");
// validateSingleKey("TestTable2");
@@ -96,7 +102,8 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testCreateAndInsertMultiKey() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable3 (`first` STRING, `second` INT, third STRING) WITH ('kudu.hash-columns' = 'first,second', 'kudu.primary-key-columns' = 'first,second')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable3 (`first` STRING, `second` INT, third STRING) WITH ('kudu.hash-columns' = 'first,second', 'kudu.primary-key-columns' = 'first,second')");
tableEnv.executeSql("INSERT INTO TestTable3 VALUES ('f', 2, 't')")
.getJobClient()
.get()
@@ -108,14 +115,16 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testSourceProjection() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable5 (`second` String, `first` STRING, `third` String) WITH ('kudu.hash-columns' = 'second', 'kudu.primary-key-columns' = 'second')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable5 (`second` String, `first` STRING, `third` String) WITH ('kudu.hash-columns' = 'second', 'kudu.primary-key-columns' = 'second')");
tableEnv.executeSql("INSERT INTO TestTable5 VALUES ('s', 'f', 't')")
.getJobClient()
.get()
.getJobExecutionResult()
.get(1, TimeUnit.MINUTES);
- tableEnv.executeSql("CREATE TABLE TestTable6 (`first` STRING, `second` String) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable6 (`first` STRING, `second` String) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
tableEnv.executeSql("INSERT INTO TestTable6 (SELECT `first`, `second` FROM TestTable5)")
.getJobClient()
.get()
@@ -128,7 +137,8 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testEmptyProjection() throws Exception {
CollectionSink.output.clear();
- tableEnv.executeSql("CREATE TABLE TestTableEP (`first` STRING, `second` STRING) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTableEP (`first` STRING, `second` STRING) WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
tableEnv.executeSql("INSERT INTO TestTableEP VALUES ('f','s')")
.getJobClient()
.get()
@@ -142,16 +152,19 @@ public class KuduCatalogTest extends KuduTestBase {
Table result = tableEnv.sqlQuery("SELECT COUNT(*) FROM TestTableEP");
- DataStream<Tuple2<Boolean, Row>> resultDataStream = tableEnv.toRetractStream(result, Types.ROW(Types.LONG));
+ DataStream<Tuple2<Boolean, Row>> resultDataStream =
+ tableEnv.toRetractStream(result, Types.ROW(Types.LONG));
resultDataStream
.map(t -> Tuple2.of(t.f0, t.f1.getField(0)))
.returns(Types.TUPLE(Types.BOOLEAN, Types.LONG))
- .addSink(new CollectionSink<>()).setParallelism(1);
+ .addSink(new CollectionSink<>())
+ .setParallelism(1);
resultDataStream.getExecutionEnvironment().execute();
- List<Tuple2<Boolean, Long>> expected = Lists.newArrayList(Tuple2.of(true, 1L), Tuple2.of(false, 1L), Tuple2.of(true, 2L));
+ List<Tuple2<Boolean, Long>> expected =
+ Lists.newArrayList(Tuple2.of(true, 1L), Tuple2.of(false, 1L), Tuple2.of(true, 2L));
assertEquals(new HashSet<>(expected), new HashSet<>(CollectionSink.output));
CollectionSink.output.clear();
@@ -163,65 +176,72 @@ public class KuduCatalogTest extends KuduTestBase {
// Creating table through catalog
KuduTableFactory tableFactory = catalog.getKuduTableFactory();
- KuduTableInfo tableInfo = KuduTableInfo.forTable("TestTable7").createTableIfNotExists(
- () ->
- Lists.newArrayList(
- new ColumnSchema
- .ColumnSchemaBuilder("k", Type.INT32)
- .key(true)
- .build(),
- new ColumnSchema
- .ColumnSchemaBuilder("v", Type.STRING)
- .build()
- ),
- () -> new CreateTableOptions()
- .setNumReplicas(1)
- .addHashPartitions(Lists.newArrayList("k"), 2));
+ KuduTableInfo tableInfo =
+ KuduTableInfo.forTable("TestTable7")
+ .createTableIfNotExists(
+ () ->
+ Lists.newArrayList(
+ new ColumnSchema.ColumnSchemaBuilder(
+ "k", Type.INT32)
+ .key(true)
+ .build(),
+ new ColumnSchema.ColumnSchemaBuilder(
+ "v", Type.STRING)
+ .build()),
+ () ->
+ new CreateTableOptions()
+ .setNumReplicas(1)
+ .addHashPartitions(Lists.newArrayList("k"), 2));
catalog.createTable(tableInfo, false);
ObjectPath path = catalog.getObjectPath("TestTable7");
CatalogTable table = catalog.getTable(path);
- List<Tuple2<Integer, String>> input = Lists.newArrayList(Tuple2.of(1, "one"), Tuple2.of(2, "two"), Tuple2.of(3, "three"));
+ List<Tuple2<Integer, String>> input =
+ Lists.newArrayList(Tuple2.of(1, "one"), Tuple2.of(2, "two"), Tuple2.of(3, "three"));
// Writing with simple sink
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(2);
- KuduWriterConfig writerConfig = KuduWriterConfig.Builder.setMasters(getMasterAddress()).build();
- env.fromCollection(input).addSink(
- new KuduSink<>(
- writerConfig,
- tableInfo,
- new TupleOperationMapper<>(
- new String[]{"k", "v"},
- AbstractSingleOperationMapper.KuduOperation.INSERT)
- )
- );
+ KuduWriterConfig writerConfig =
+ KuduWriterConfig.Builder.setMasters(getMasterAddress()).build();
+ env.fromCollection(input)
+ .addSink(
+ new KuduSink<>(
+ writerConfig,
+ tableInfo,
+ new TupleOperationMapper<>(
+ new String[] {"k", "v"},
+ AbstractSingleOperationMapper.KuduOperation.INSERT)));
env.execute();
// Reading and validating data
env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(2);
CollectionSink.output.clear();
- tableFactory.createTableSource(path, table)
+ tableFactory
+ .createTableSource(path, table)
.getDataStream(env)
.map(row -> Tuple2.of((int) row.getField(0), (String) row.getField(1)))
- .returns(new TypeHint<Tuple2<Integer, String>>() {
- })
- .addSink(new CollectionSink<>()).setParallelism(1);
+ .returns(new TypeHint<Tuple2<Integer, String>>() {})
+ .addSink(new CollectionSink<>())
+ .setParallelism(1);
env.execute();
- List<Tuple2<Integer, String>> expected = Lists.newArrayList(Tuple2.of(1, "one"), Tuple2.of(2, "two"), Tuple2.of(3, "three"));
+ List<Tuple2<Integer, String>> expected =
+ Lists.newArrayList(Tuple2.of(1, "one"), Tuple2.of(2, "two"), Tuple2.of(3, "three"));
assertEquals(new HashSet<>(expected), new HashSet<>(CollectionSink.output));
CollectionSink.output.clear();
}
@Test
public void testTimestamp() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTableTsC (`first` STRING, `second` TIMESTAMP(3)) " +
- "WITH ('kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
- tableEnv.executeSql("INSERT INTO TestTableTsC values ('f', TIMESTAMP '2020-01-01 12:12:12.123456')")
+ tableEnv.executeSql(
+ "CREATE TABLE TestTableTsC (`first` STRING, `second` TIMESTAMP(3)) "
+ + "WITH ('kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
+ tableEnv.executeSql(
+ "INSERT INTO TestTableTsC values ('f', TIMESTAMP '2020-01-01 12:12:12.123456')")
.getJobClient()
.get()
.getJobExecutionResult()
@@ -241,14 +261,16 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testDatatypes() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable8 (`first` STRING, `second` BOOLEAN, `third` BYTES," +
- "`fourth` TINYINT, `fifth` SMALLINT, `sixth` INT, `seventh` BIGINT, `eighth` FLOAT, `ninth` DOUBLE, " +
- "`tenth` TIMESTAMP)" +
- "WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
-
- tableEnv.executeSql("INSERT INTO TestTable8 values ('f', false, cast('bbbb' as BYTES), cast(12 as TINYINT)," +
- "cast(34 as SMALLINT), 56, cast(78 as BIGINT), cast(3.14 as FLOAT), cast(1.2345 as DOUBLE)," +
- "TIMESTAMP '2020-04-15 12:34:56.123') ")
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable8 (`first` STRING, `second` BOOLEAN, `third` BYTES,"
+ + "`fourth` TINYINT, `fifth` SMALLINT, `sixth` INT, `seventh` BIGINT, `eighth` FLOAT, `ninth` DOUBLE, "
+ + "`tenth` TIMESTAMP)"
+ + "WITH ('kudu.hash-columns' = 'first', 'kudu.primary-key-columns' = 'first')");
+
+ tableEnv.executeSql(
+ "INSERT INTO TestTable8 values ('f', false, cast('bbbb' as BYTES), cast(12 as TINYINT),"
+ + "cast(34 as SMALLINT), 56, cast(78 as BIGINT), cast(3.14 as FLOAT), cast(1.2345 as DOUBLE),"
+ + "TIMESTAMP '2020-04-15 12:34:56.123') ")
.getJobClient()
.get()
.getJobExecutionResult()
@@ -259,15 +281,24 @@ public class KuduCatalogTest extends KuduTestBase {
@Test
public void testMissingPropertiesCatalog() throws Exception {
- assertThrows(TableException.class,
- () -> tableEnv.executeSql("CREATE TABLE TestTable9a (`first` STRING, `second` String) " +
- "WITH ('kudu.primary-key-columns' = 'second')"));
- assertThrows(TableException.class,
- () -> tableEnv.executeSql("CREATE TABLE TestTable9b (`first` STRING, `second` String) " +
- "WITH ('kudu.hash-columns' = 'first')"));
- assertThrows(TableException.class,
- () -> tableEnv.executeSql("CREATE TABLE TestTable9b (`first` STRING, `second` String) " +
- "WITH ('kudu.primary-key-columns' = 'second', 'kudu.hash-columns' = 'first')"));
+ assertThrows(
+ TableException.class,
+ () ->
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable9a (`first` STRING, `second` String) "
+ + "WITH ('kudu.primary-key-columns' = 'second')"));
+ assertThrows(
+ TableException.class,
+ () ->
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable9b (`first` STRING, `second` String) "
+ + "WITH ('kudu.hash-columns' = 'first')"));
+ assertThrows(
+ TableException.class,
+ () ->
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable9b (`first` STRING, `second` String) "
+ + "WITH ('kudu.primary-key-columns' = 'second', 'kudu.hash-columns' = 'first')"));
}
private void validateManyTypes(String tableName) throws Exception {
@@ -324,13 +355,12 @@ public class KuduCatalogTest extends KuduTestBase {
assertEquals("t", rows.get(0).getString("third"));
}
- public static class CollectionSink<T> implements SinkFunction<T> {
+ private static class CollectionSink<T> implements SinkFunction<T> {
public static List<Object> output = Collections.synchronizedList(new ArrayList<>());
- public void invoke(T value, SinkFunction.Context context) throws Exception {
+ public void invoke(T value, SinkFunction.Context context) {
output.add(value);
}
-
}
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableFactoryTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableFactoryTest.java
index 0375c68..69b8e88 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableFactoryTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableFactoryTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -31,6 +32,7 @@ import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.table.factories.TableFactoryService;
import org.apache.flink.table.factories.TableSinkFactory;
import org.apache.flink.table.sinks.TableSink;
+
import org.apache.kudu.Type;
import org.apache.kudu.client.KuduScanner;
import org.apache.kudu.client.KuduTable;
@@ -40,36 +42,51 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.sql.Timestamp;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+/** Tets for table factory. */
public class KuduTableFactoryTest extends KuduTestBase {
private StreamTableEnvironment tableEnv;
private String kuduMasters;
@BeforeEach
public void init() {
- StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment().setParallelism(1);
+ StreamExecutionEnvironment env =
+ StreamExecutionEnvironment.getExecutionEnvironment().setParallelism(1);
tableEnv = KuduTableTestUtils.createTableEnvWithBlinkPlannerStreamingMode(env);
kuduMasters = getMasterAddress();
}
@Test
public void testMissingMasters() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable11 (`first` STRING, `second` INT) " +
- "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11')");
- assertThrows(TableException.class,
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable11 (`first` STRING, `second` INT) "
+ + "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11')");
+ assertThrows(
+ TableException.class,
() -> tableEnv.executeSql("INSERT INTO TestTable11 values ('f', 1)"));
}
@Test
public void testNonExistingTable() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable11 (`first` STRING, `second` INT) " +
- "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11', 'kudu.masters'='" + kuduMasters + "')");
- JobClient jobClient = tableEnv.executeSql("INSERT INTO TestTable11 values ('f', 1)").getJobClient().get();
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable11 (`first` STRING, `second` INT) "
+ + "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11', 'kudu.masters'='"
+ + kuduMasters
+ + "')");
+ JobClient jobClient =
+ tableEnv.executeSql("INSERT INTO TestTable11 values ('f', 1)").getJobClient().get();
try {
jobClient.getJobExecutionResult().get();
fail();
@@ -80,9 +97,12 @@ public class KuduTableFactoryTest extends KuduTestBase {
@Test
public void testCreateTable() throws Exception {
- tableEnv.executeSql("CREATE TABLE TestTable11 (`first` STRING, `second` STRING) " +
- "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11', 'kudu.masters'='" + kuduMasters + "', " +
- "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable11 (`first` STRING, `second` STRING) "
+ + "WITH ('connector.type'='kudu', 'kudu.table'='TestTable11', 'kudu.masters'='"
+ + kuduMasters
+ + "', "
+ + "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
tableEnv.executeSql("INSERT INTO TestTable11 values ('f', 's')")
.getJobClient()
@@ -97,10 +117,14 @@ public class KuduTableFactoryTest extends KuduTestBase {
public void testTimestamp() throws Exception {
// Timestamp should be bridged to sql.Timestamp
// Test it when creating the table...
- tableEnv.executeSql("CREATE TABLE TestTableTs (`first` STRING, `second` TIMESTAMP(3)) " +
- "WITH ('connector.type'='kudu', 'kudu.masters'='" + kuduMasters + "', " +
- "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
- tableEnv.executeSql("INSERT INTO TestTableTs values ('f', TIMESTAMP '2020-01-01 12:12:12.123456')")
+ tableEnv.executeSql(
+ "CREATE TABLE TestTableTs (`first` STRING, `second` TIMESTAMP(3)) "
+ + "WITH ('connector.type'='kudu', 'kudu.masters'='"
+ + kuduMasters
+ + "', "
+ + "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
+ tableEnv.executeSql(
+ "INSERT INTO TestTableTs values ('f', TIMESTAMP '2020-01-01 12:12:12.123456')")
.getJobClient()
.get()
.getJobExecutionResult()
@@ -120,18 +144,22 @@ public class KuduTableFactoryTest extends KuduTestBase {
scanner.forEach(sc -> results.add(sc.getTimestamp("second")));
assertEquals(2, results.size());
- List<Timestamp> expected = Lists.newArrayList(
- Timestamp.valueOf("2020-01-01 12:12:12.123"),
- Timestamp.valueOf("2020-02-02 23:23:23"));
+ List<Timestamp> expected =
+ Lists.newArrayList(
+ Timestamp.valueOf("2020-01-01 12:12:12.123"),
+ Timestamp.valueOf("2020-02-02 23:23:23"));
assertEquals(new HashSet<>(expected), results);
}
@Test
public void testExistingTable() throws Exception {
// Creating a table
- tableEnv.executeSql("CREATE TABLE TestTable12 (`first` STRING, `second` STRING) " +
- "WITH ('connector.type'='kudu', 'kudu.table'='TestTable12', 'kudu.masters'='" + kuduMasters + "', " +
- "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable12 (`first` STRING, `second` STRING) "
+ + "WITH ('connector.type'='kudu', 'kudu.table'='TestTable12', 'kudu.masters'='"
+ + kuduMasters
+ + "', "
+ + "'kudu.hash-columns'='first', 'kudu.primary-key-columns'='first')");
tableEnv.executeSql("INSERT INTO TestTable12 values ('f', 's')")
.getJobClient()
@@ -140,8 +168,11 @@ public class KuduTableFactoryTest extends KuduTestBase {
.get(1, TimeUnit.MINUTES);
// Then another one in SQL that refers to the previously created one
- tableEnv.executeSql("CREATE TABLE TestTable12b (`first` STRING, `second` STRING) " +
- "WITH ('connector.type'='kudu', 'kudu.table'='TestTable12', 'kudu.masters'='" + kuduMasters + "')");
+ tableEnv.executeSql(
+ "CREATE TABLE TestTable12b (`first` STRING, `second` STRING) "
+ + "WITH ('connector.type'='kudu', 'kudu.table'='TestTable12', 'kudu.masters'='"
+ + kuduMasters
+ + "')");
tableEnv.executeSql("INSERT INTO TestTable12b values ('f2','s2')")
.getJobClient()
.get()
@@ -163,10 +194,11 @@ public class KuduTableFactoryTest extends KuduTestBase {
@Test
public void testTableSink() {
- final TableSchema schema = TableSchema.builder()
- .field("first", DataTypes.STRING())
- .field("second", DataTypes.STRING())
- .build();
+ final TableSchema schema =
+ TableSchema.builder()
+ .field("first", DataTypes.STRING())
+ .field("second", DataTypes.STRING())
+ .build();
final Map<String, String> properties = new HashMap<>();
properties.put("connector.type", "kudu");
properties.put("kudu.masters", kuduMasters);
@@ -176,15 +208,19 @@ public class KuduTableFactoryTest extends KuduTestBase {
properties.put("kudu.flush-interval", "10000");
properties.put("kudu.max-buffer-size", "10000");
- KuduWriterConfig.Builder builder = KuduWriterConfig.Builder.setMasters(kuduMasters)
- .setFlushInterval(10000)
- .setMaxBufferSize(10000)
- .setIgnoreDuplicate(true)
- .setIgnoreNotFound(true);
+ KuduWriterConfig.Builder builder =
+ KuduWriterConfig.Builder.setMasters(kuduMasters)
+ .setFlushInterval(10000)
+ .setMaxBufferSize(10000)
+ .setIgnoreDuplicate(true)
+ .setIgnoreNotFound(true);
KuduTableInfo kuduTableInfo = KuduTableInfo.forTable("TestTable12");
KuduTableSink expected = new KuduTableSink(builder, kuduTableInfo, schema);
- final TableSink<?> actualSink = TableFactoryService.find(TableSinkFactory.class, properties)
- .createTableSink(ObjectPath.fromString("default.TestTable12"), new CatalogTableImpl(schema, properties, null));
+ final TableSink<?> actualSink =
+ TableFactoryService.find(TableSinkFactory.class, properties)
+ .createTableSink(
+ ObjectPath.fromString("default.TestTable12"),
+ new CatalogTableImpl(schema, properties, null));
assertEquals(expected, actualSink);
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceITCase.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceITCase.java
index 4a53198..9d2b378 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceITCase.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceITCase.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -21,6 +22,7 @@ import org.apache.flink.connectors.kudu.connector.KuduTestBase;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.types.Row;
import org.apache.flink.util.CloseableIterator;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -29,9 +31,7 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
-/**
- * Integration tests for {@link KuduTableSource}.
- */
+/** Integration tests for {@link KuduTableSource}. */
public class KuduTableSourceITCase extends KuduTestBase {
private TableEnvironment tableEnv;
private KuduCatalog catalog;
@@ -48,7 +48,8 @@ public class KuduTableSourceITCase extends KuduTestBase {
@Test
void testFullBatchScan() throws Exception {
- CloseableIterator<Row> it = tableEnv.executeSql("select * from books order by id").collect();
+ CloseableIterator<Row> it =
+ tableEnv.executeSql("select * from books order by id").collect();
List<Row> results = new ArrayList<>();
it.forEachRemaining(results::add);
assertEquals(5, results.size());
@@ -56,12 +57,14 @@ public class KuduTableSourceITCase extends KuduTestBase {
tableEnv.executeSql("DROP TABLE books");
}
-
@Test
void testScanWithProjectionAndFilter() throws Exception {
// (price > 30 and price < 40)
- CloseableIterator<Row> it = tableEnv.executeSql("SELECT title FROM books WHERE id IN (1003, 1004) and " +
- "quantity < 40").collect();
+ CloseableIterator<Row> it =
+ tableEnv.executeSql(
+ "SELECT title FROM books WHERE id IN (1003, 1004) and "
+ + "quantity < 40")
+ .collect();
List<Row> results = new ArrayList<>();
it.forEachRemaining(results::add);
assertEquals(1, results.size());
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceTest.java
index d4101aa..1407dda 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableSourceTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -22,10 +23,15 @@ import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.table.catalog.exceptions.TableNotExistException;
-import org.apache.flink.table.expressions.*;
+import org.apache.flink.table.expressions.CallExpression;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.expressions.FieldReferenceExpression;
+import org.apache.flink.table.expressions.ResolvedExpression;
+import org.apache.flink.table.expressions.ValueLiteralExpression;
import org.apache.flink.table.functions.ScalarFunction;
import org.apache.flink.table.functions.ScalarFunctionDefinition;
import org.apache.flink.table.types.DataType;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -38,18 +44,23 @@ import java.util.List;
import static java.util.Collections.singletonList;
import static org.apache.flink.table.functions.BuiltInFunctionDefinitions.AND;
import static org.apache.flink.table.functions.BuiltInFunctionDefinitions.EQUALS;
-import static org.junit.Assert.*;
-
-/**
- * Unit Tests for {@link KuduTableSource}.
- */
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/** Unit Tests for {@link KuduTableSource}. */
public class KuduTableSourceTest extends KuduTestBase {
private KuduTableSource kuduTableSource;
private KuduCatalog catalog;
private static final ScalarFunction DUMMY_FUNCTION = new ScalarFunction() {
- // dummy
- };
+ // dummy
+ };
@BeforeEach
public void init() {
@@ -58,7 +69,8 @@ public class KuduTableSourceTest extends KuduTestBase {
catalog = new KuduCatalog(getMasterAddress());
ObjectPath op = new ObjectPath("default_database", "books");
try {
- kuduTableSource = catalog.getKuduTableFactory().createTableSource(op, catalog.getTable(op));
+ kuduTableSource =
+ catalog.getKuduTableFactory().createTableSource(op, catalog.getTable(op));
} catch (TableNotExistException e) {
fail(e.getMessage());
}
@@ -76,20 +88,21 @@ public class KuduTableSourceTest extends KuduTestBase {
assertNotNull(tableSchema);
assertArrayEquals(getFieldNames(), tableSchema.getFieldNames());
assertArrayEquals(getFieldDataTypes(), tableSchema.getFieldDataTypes());
-
}
@Test
void testGetProducedDataType() throws Exception {
DataType producedDataType = kuduTableSource.getProducedDataType();
assertNotNull(producedDataType);
- assertEquals(getReturnDataType(getFieldNames(), getFieldDataTypes()).notNull(), producedDataType);
+ assertEquals(
+ getReturnDataType(getFieldNames(), getFieldDataTypes()).notNull(),
+ producedDataType);
}
@Test
void testProjectFields() throws Exception {
- KuduTableSource projectedTableSource = (KuduTableSource) kuduTableSource.projectFields(
- new int[]{3, 4, 1});
+ KuduTableSource projectedTableSource =
+ (KuduTableSource) kuduTableSource.projectFields(new int[] {3, 4, 1});
// ensure copy is returned
assertTrue(kuduTableSource != projectedTableSource);
// ensure table schema is identical
@@ -98,39 +111,37 @@ public class KuduTableSourceTest extends KuduTestBase {
String[] fieldNames = getFieldNames();
DataType[] fieldDataTypes = getFieldDataTypes();
String[] projectedFieldNames = new String[] {fieldNames[3], fieldNames[4], fieldNames[1]};
- DataType[] projectedDataTypes = new DataType[] {fieldDataTypes[3], fieldDataTypes[4],
- fieldDataTypes[1]};
- assertEquals(getReturnDataType(projectedFieldNames, projectedDataTypes),
- projectedTableSource.getProducedDataType());
+ DataType[] projectedDataTypes =
+ new DataType[] {fieldDataTypes[3], fieldDataTypes[4], fieldDataTypes[1]};
+ assertEquals(
+ getReturnDataType(projectedFieldNames, projectedDataTypes),
+ projectedTableSource.getProducedDataType());
}
@Test
void testApplyPredicate() throws Exception {
// expressions for supported predicates
- FieldReferenceExpression fieldReferenceExpression = new FieldReferenceExpression(
- "id", DataTypes.INT(), 0, 0);
+ FieldReferenceExpression fieldReferenceExpression =
+ new FieldReferenceExpression("id", DataTypes.INT(), 0, 0);
ValueLiteralExpression valueLiteralExpression = new ValueLiteralExpression(1);
- List<ResolvedExpression> args = new ArrayList<>(
- Arrays.asList(fieldReferenceExpression, valueLiteralExpression));
- Expression supportedPred = new CallExpression(
- EQUALS,
- args,
- DataTypes.BOOLEAN());
+ List<ResolvedExpression> args =
+ new ArrayList<>(Arrays.asList(fieldReferenceExpression, valueLiteralExpression));
+ Expression supportedPred = new CallExpression(EQUALS, args, DataTypes.BOOLEAN());
// unsupported predicate
- Expression unsupportedPred = new CallExpression(
- new ScalarFunctionDefinition("dummy", DUMMY_FUNCTION),
- singletonList(new ValueLiteralExpression(1)),
- DataTypes.INT());
+ Expression unsupportedPred =
+ new CallExpression(
+ new ScalarFunctionDefinition("dummy", DUMMY_FUNCTION),
+ singletonList(new ValueLiteralExpression(1)),
+ DataTypes.INT());
// invalid predicate
- Expression invalidPred = new CallExpression(
- AND,
- Collections.emptyList(),
- DataTypes.ARRAY(DataTypes.INT()));
+ Expression invalidPred =
+ new CallExpression(AND, Collections.emptyList(), DataTypes.ARRAY(DataTypes.INT()));
- ArrayList<Expression> preds = new ArrayList<>(
- Arrays.asList(supportedPred, unsupportedPred, invalidPred));
+ ArrayList<Expression> preds =
+ new ArrayList<>(Arrays.asList(supportedPred, unsupportedPred, invalidPred));
// apply predicates on TableSource
- KuduTableSource filteredTableSource = (KuduTableSource) kuduTableSource.applyPredicate(preds);
+ KuduTableSource filteredTableSource =
+ (KuduTableSource) kuduTableSource.applyPredicate(preds);
// ensure the unable push down expressions are reserved
assertEquals(preds.size(), 2);
assertSame(unsupportedPred, preds.get(0));
@@ -140,21 +151,24 @@ public class KuduTableSourceTest extends KuduTestBase {
// ensure table schema is identical
assertEquals(kuduTableSource.getTableSchema(), filteredTableSource.getTableSchema());
// ensure return type is identical
- assertEquals(kuduTableSource.getProducedDataType(), filteredTableSource.getProducedDataType());
+ assertEquals(
+ kuduTableSource.getProducedDataType(), filteredTableSource.getProducedDataType());
// ensure filter pushdown is correct
assertTrue(filteredTableSource.isFilterPushedDown());
assertFalse(kuduTableSource.isFilterPushedDown());
}
private String[] getFieldNames() {
- return new String[] {
- "id", "title", "author", "price", "quantity"
- };
+ return new String[] {"id", "title", "author", "price", "quantity"};
}
private DataType[] getFieldDataTypes() {
- return new DataType[]{
- DataTypes.INT(), DataTypes.STRING(), DataTypes.STRING(), DataTypes.DOUBLE(), DataTypes.INT(),
+ return new DataType[] {
+ DataTypes.INT(),
+ DataTypes.STRING(),
+ DataTypes.STRING(),
+ DataTypes.DOUBLE(),
+ DataTypes.INT(),
};
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableTestUtils.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableTestUtils.java
index affdd04..aadb031 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableTestUtils.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/KuduTableTestUtils.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
@@ -23,19 +24,25 @@ import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import static org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM;
+/** Table API test utilities. */
public class KuduTableTestUtils {
- public static StreamTableEnvironment createTableEnvWithBlinkPlannerStreamingMode(StreamExecutionEnvironment env) {
+ public static StreamTableEnvironment createTableEnvWithBlinkPlannerStreamingMode(
+ StreamExecutionEnvironment env) {
EnvironmentSettings settings = EnvironmentSettings.newInstance().inStreamingMode().build();
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings);
- tableEnv.getConfig().getConfiguration().setInteger(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM.key(), 1);
+ tableEnv.getConfig()
+ .getConfiguration()
+ .setInteger(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM.key(), 1);
return tableEnv;
}
public static TableEnvironment createTableEnvWithBlinkPlannerBatchMode() {
EnvironmentSettings settings = EnvironmentSettings.newInstance().inBatchMode().build();
TableEnvironment tableEnv = TableEnvironment.create(settings);
- tableEnv.getConfig().getConfiguration().setInteger(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM.key(), 1);
+ tableEnv.getConfig()
+ .getConfiguration()
+ .setInteger(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM.key(), 1);
return tableEnv;
}
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSinkTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSinkTest.java
index 8dd1a79..c198048 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSinkTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSinkTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -23,15 +24,14 @@ import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.types.Row;
import org.apache.flink.util.CloseableIterator;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-/**
- * Unit Tests for {@link KuduDynamicTableSink}.
- */
+/** Unit Tests for {@link KuduDynamicTableSink}. */
public class KuduDynamicSinkTest extends KuduTestBase {
public static final String INPUT_TABLE = "books";
public static StreamExecutionEnvironment env;
@@ -53,30 +53,32 @@ public class KuduDynamicSinkTest extends KuduTestBase {
@Test
public void testKuduSink() throws Exception {
- String createSql = "CREATE TABLE "
- + INPUT_TABLE
- + "("
- + "id int,"
- + "title string,"
- + "author string,"
- + "price double,"
- + "quantity int"
- + ") WITH ("
- + " 'connector'='kudu',"
- + " 'kudu.masters'='"
- + 123245
- + "',"
- + " 'kudu.table'='"
- + INPUT_TABLE
- + "','kudu.primary-key-columns'='id"
- + "','kudu.max-buffer-size'='1024"
- + "','kudu.flush-interval'='1000"
- + "','kudu.operation-timeout'='500"
- + "','kudu.ignore-not-found'='true"
- + "','kudu.ignore-not-found'='true'"
- + ")";
+ String createSql =
+ "CREATE TABLE "
+ + INPUT_TABLE
+ + "("
+ + "id int,"
+ + "title string,"
+ + "author string,"
+ + "price double,"
+ + "quantity int"
+ + ") WITH ("
+ + " 'connector'='kudu',"
+ + " 'kudu.masters'='"
+ + 123245
+ + "',"
+ + " 'kudu.table'='"
+ + INPUT_TABLE
+ + "','kudu.primary-key-columns'='id"
+ + "','kudu.max-buffer-size'='1024"
+ + "','kudu.flush-interval'='1000"
+ + "','kudu.operation-timeout'='500"
+ + "','kudu.ignore-not-found'='true"
+ + "','kudu.ignore-not-found'='true'"
+ + ")";
tEnv.executeSql(createSql);
- tEnv.executeSql("insert into " + INPUT_TABLE + " values(1006,'test title','test author',10.1,10)");
+ tEnv.executeSql(
+ "insert into " + INPUT_TABLE + " values(1006,'test title','test author',10.1,10)");
CloseableIterator<Row> collected =
tEnv.executeSql("select * from " + INPUT_TABLE + " where id =1006").collect();
assertNotNull(collected);
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSourceTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSourceTest.java
index 377ac2d..1741ca0 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSourceTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduDynamicSourceTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -23,6 +24,7 @@ import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.types.Row;
import org.apache.flink.util.CollectionUtil;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -35,9 +37,7 @@ import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-/**
- * Unit Tests for {@link KuduDynamicTableSource}.
- */
+/** Unit Tests for {@link KuduDynamicTableSource}. */
public class KuduDynamicSourceTest extends KuduTestBase {
public static final String INPUT_TABLE = "books";
public static StreamExecutionEnvironment env;
@@ -77,8 +77,8 @@ public class KuduDynamicSourceTest extends KuduTestBase {
+ " 'kudu.table'='"
+ INPUT_TABLE
+ "',"
- + "'kudu.scan.row-size'='10'," +
- "'kudu.primary-key-columns'='id'"
+ + "'kudu.scan.row-size'='10',"
+ + "'kudu.primary-key-columns'='id'"
+ ")");
Iterator<Row> collected = tEnv.executeSql("SELECT * FROM " + INPUT_TABLE).collect();
@@ -104,13 +104,12 @@ public class KuduDynamicSourceTest extends KuduTestBase {
+ " 'kudu.table'='"
+ INPUT_TABLE
+ "',"
- + "'kudu.scan.row-size'='10'," +
- "'kudu.primary-key-columns'='id'"
+ + "'kudu.scan.row-size'='10',"
+ + "'kudu.primary-key-columns'='id'"
+ ")");
Iterator<Row> collected =
- tEnv.executeSql("SELECT id,title,author FROM " + INPUT_TABLE)
- .collect();
+ tEnv.executeSql("SELECT id,title,author FROM " + INPUT_TABLE).collect();
assertNotNull(collected);
List<String> result =
CollectionUtil.iteratorToList(collected).stream()
@@ -148,8 +147,8 @@ public class KuduDynamicSourceTest extends KuduTestBase {
+ " 'kudu.table'='"
+ INPUT_TABLE
+ "',"
- + "'kudu.scan.row-size'='10'," +
- "'kudu.primary-key-columns'='id'"
+ + "'kudu.scan.row-size'='10',"
+ + "'kudu.primary-key-columns'='id'"
+ ")");
Iterator<Row> collected =
@@ -181,8 +180,8 @@ public class KuduDynamicSourceTest extends KuduTestBase {
+ " 'kudu.table'='"
+ INPUT_TABLE
+ "',"
- + "'kudu.scan.row-size'='10'," +
- "'kudu.primary-key-columns'='id'"
+ + "'kudu.scan.row-size'='10',"
+ + "'kudu.primary-key-columns'='id'"
+ ")");
tEnv.executeSql(
@@ -203,11 +202,13 @@ public class KuduDynamicSourceTest extends KuduTestBase {
+ ")");
Iterator<Row> collected =
- tEnv.executeSql("SELECT d.id, isbn, title FROM datagen as d"
- + " JOIN " + INPUT_TABLE
- + " FOR SYSTEM_TIME AS OF d.proctime AS k"
- + " ON d.id=k.id"
- + " WHERE k.title='Java for dummies'")
+ tEnv.executeSql(
+ "SELECT d.id, isbn, title FROM datagen as d"
+ + " JOIN "
+ + INPUT_TABLE
+ + " FOR SYSTEM_TIME AS OF d.proctime AS k"
+ + " ON d.id=k.id"
+ + " WHERE k.title='Java for dummies'")
.collect();
assertNotNull(collected);
List<String> result =
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduRowDataLookupFunctionTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduRowDataLookupFunctionTest.java
index bc3d51a..5775d5f 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduRowDataLookupFunctionTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/table/dynamic/KuduRowDataLookupFunctionTest.java
@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.table.dynamic;
import org.apache.flink.connectors.kudu.connector.KuduTableInfo;
@@ -23,6 +24,7 @@ import org.apache.flink.connectors.kudu.table.function.lookup.KuduLookupOptions;
import org.apache.flink.connectors.kudu.table.function.lookup.KuduRowDataLookupFunction;
import org.apache.flink.table.data.RowData;
import org.apache.flink.util.Collector;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -33,10 +35,7 @@ import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-/**
- * Unit Tests for {@link KuduRowDataLookupFunction}.
- */
+/** Unit Tests for {@link KuduRowDataLookupFunction}. */
public class KuduRowDataLookupFunctionTest extends KuduTestBase {
public static final String INPUT_TABLE = "books";
public static KuduTableInfo tableInfo;
@@ -57,8 +56,8 @@ public class KuduRowDataLookupFunctionTest extends KuduTestBase {
public void testEval() throws Exception {
KuduLookupOptions lookupOptions = KuduLookupOptions.builder().build();
- KuduRowDataLookupFunction lookupFunction = buildRowDataLookupFunction(lookupOptions, new String[]{
- "id"});
+ KuduRowDataLookupFunction lookupFunction =
+ buildRowDataLookupFunction(lookupOptions, new String[] {"id"});
ListOutputCollector collector = new ListOutputCollector();
lookupFunction.setCollector(collector);
@@ -80,14 +79,15 @@ public class KuduRowDataLookupFunctionTest extends KuduTestBase {
@Test
public void testCacheEval() throws Exception {
- KuduLookupOptions lookupOptions = KuduLookupOptions.builder()
- .withCacheMaxSize(1024)
- .withMaxRetryTimes(3)
- .withCacheExpireMs(10)
- .build();
+ KuduLookupOptions lookupOptions =
+ KuduLookupOptions.builder()
+ .withCacheMaxSize(1024)
+ .withMaxRetryTimes(3)
+ .withCacheExpireMs(10)
+ .build();
- KuduRowDataLookupFunction lookupFunction = buildRowDataLookupFunction(lookupOptions, new String[]{
- "id"});
+ KuduRowDataLookupFunction lookupFunction =
+ buildRowDataLookupFunction(lookupOptions, new String[] {"id"});
ListOutputCollector collector = new ListOutputCollector();
lookupFunction.setCollector(collector);
@@ -107,10 +107,10 @@ public class KuduRowDataLookupFunctionTest extends KuduTestBase {
assertNotNull(result);
}
- private KuduRowDataLookupFunction buildRowDataLookupFunction(KuduLookupOptions lookupOptions, String[] keyNames) {
- KuduReaderConfig config = KuduReaderConfig.Builder.setMasters(getMasterAddress())
- .setRowLimit(10)
- .build();
+ private KuduRowDataLookupFunction buildRowDataLookupFunction(
+ KuduLookupOptions lookupOptions, String[] keyNames) {
+ KuduReaderConfig config =
+ KuduReaderConfig.Builder.setMasters(getMasterAddress()).setRowLimit(10).build();
return new KuduRowDataLookupFunction.Builder()
.kuduReaderConfig(config)
.kuduLookupOptions(lookupOptions)
@@ -118,18 +118,12 @@ public class KuduRowDataLookupFunctionTest extends KuduTestBase {
.projectedFields(getFieldNames())
.tableInfo(tableInfo)
.build();
-
}
private String[] getFieldNames() {
- return new String[]{
- "id", "title", "author", "price", "quantity"
- };
+ return new String[] {"id", "title", "author", "price", "quantity"};
}
- /**
- * ouput collector
- */
private static final class ListOutputCollector implements Collector<RowData> {
private final List<RowData> output = new ArrayList<>();
@@ -140,8 +134,7 @@ public class KuduRowDataLookupFunctionTest extends KuduTestBase {
}
@Override
- public void close() {
- }
+ public void close() {}
public List<RowData> getOutputs() {
return output;
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/AbstractOperationTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/AbstractOperationTest.java
index 12d82a9..c5f7d28 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/AbstractOperationTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/AbstractOperationTest.java
@@ -14,32 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.writer;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
+
import org.apache.kudu.Schema;
-import org.apache.kudu.client.*;
+import org.apache.kudu.client.Delete;
+import org.apache.kudu.client.Insert;
+import org.apache.kudu.client.KuduTable;
+import org.apache.kudu.client.PartialRow;
+import org.apache.kudu.client.Update;
+import org.apache.kudu.client.Upsert;
import org.junit.jupiter.api.BeforeEach;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.mockito.Mockito.when;
+/** Base class for operation tests. */
public abstract class AbstractOperationTest {
- public static final Schema tableSchema = KuduTestBase.booksTableInfo("test_table", true).getSchema();
- @Mock
- Insert mockInsert;
- @Mock
- Upsert mockUpsert;
- @Mock
- Update mockUpdate;
- @Mock
- Delete mockDelete;
- @Mock
- KuduTable mockTable;
- @Mock
- PartialRow mockPartialRow;
+ public static final Schema TABLE_SCHEMA =
+ KuduTestBase.booksTableInfo("test_table", true).getSchema();
+ @Mock Insert mockInsert;
+ @Mock Upsert mockUpsert;
+ @Mock Update mockUpdate;
+ @Mock Delete mockDelete;
+ @Mock KuduTable mockTable;
+ @Mock PartialRow mockPartialRow;
@BeforeEach
public void setup() {
@@ -52,6 +55,6 @@ public abstract class AbstractOperationTest {
when(mockTable.newUpsert()).thenReturn(mockUpsert);
when(mockTable.newUpdate()).thenReturn(mockUpdate);
when(mockTable.newDelete()).thenReturn(mockDelete);
- when(mockTable.getSchema()).thenReturn(tableSchema);
+ when(mockTable.getSchema()).thenReturn(TABLE_SCHEMA);
}
}
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/PojoOperationMapperTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/PojoOperationMapperTest.java
index f03c469..2054864 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/PojoOperationMapperTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/PojoOperationMapperTest.java
@@ -21,6 +21,7 @@ import org.apache.flink.connectors.kudu.connector.KuduTestBase;
import org.apache.flink.connectors.kudu.connector.KuduTestBase.BookInfo;
import org.apache.flink.connectors.kudu.connector.writer.AbstractSingleOperationMapper;
import org.apache.flink.connectors.kudu.connector.writer.PojoOperationMapper;
+
import org.apache.kudu.client.Operation;
import org.apache.kudu.client.PartialRow;
import org.junit.jupiter.api.Test;
@@ -30,12 +31,17 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
+/** Tests for {@link PojoOperationMapper}. */
public class PojoOperationMapperTest extends AbstractOperationTest {
@Test
void testPojoMapper() {
- PojoOperationMapper<BookInfo> mapper = new PojoOperationMapper<>(BookInfo.class, KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ PojoOperationMapper<BookInfo> mapper =
+ new PojoOperationMapper<>(
+ BookInfo.class,
+ KuduTestBase.columns,
+ AbstractSingleOperationMapper.KuduOperation.INSERT);
BookInfo bookInfo = KuduTestBase.booksDataPojo().get(0);
@@ -60,7 +66,11 @@ public class PojoOperationMapperTest extends AbstractOperationTest {
@Test
public void testFieldInheritance() {
- PojoOperationMapper<Second> mapper = new PojoOperationMapper<>(Second.class, new String[]{"s1", "i1", "i2"}, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ PojoOperationMapper<Second> mapper =
+ new PojoOperationMapper<>(
+ Second.class,
+ new String[] {"s1", "i1", "i2"},
+ AbstractSingleOperationMapper.KuduOperation.INSERT);
Second s = new Second();
assertEquals("s1", mapper.getField(s, 0));
assertEquals(1, mapper.getField(s, 1));
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowDataUpsertOperationMapperTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowDataUpsertOperationMapperTest.java
index 3cda636..28f91d5 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowDataUpsertOperationMapperTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowDataUpsertOperationMapperTest.java
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.writer;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
import org.apache.flink.connectors.kudu.connector.writer.RowDataUpsertOperationMapper;
import org.apache.flink.table.data.RowData;
+
import org.apache.kudu.client.Operation;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -28,9 +30,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
-/**
- * Unit Tests for {@link RowDataUpsertOperationMapper}.
- */
+/** Unit Tests for {@link RowDataUpsertOperationMapper}. */
public class RowDataUpsertOperationMapperTest extends AbstractOperationTest {
@Test
@@ -42,7 +42,6 @@ public class RowDataUpsertOperationMapperTest extends AbstractOperationTest {
Assertions.assertEquals(inputRow.getInt(0), mapper.getField(inputRow, 0));
}
-
@Test
void testCorrectOperationUpsert() {
RowDataUpsertOperationMapper mapper =
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowOperationMapperTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowOperationMapperTest.java
index 3aeb673..57c46c7 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowOperationMapperTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/RowOperationMapperTest.java
@@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.writer;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
import org.apache.flink.connectors.kudu.connector.writer.AbstractSingleOperationMapper;
import org.apache.flink.connectors.kudu.connector.writer.RowOperationMapper;
import org.apache.flink.types.Row;
+
import org.apache.kudu.client.Operation;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -29,11 +31,14 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
+/** Tests for {@link RowOperationMapper}. */
public class RowOperationMapperTest extends AbstractOperationTest {
@Test
void testGetField() {
- RowOperationMapper mapper = new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ RowOperationMapper mapper =
+ new RowOperationMapper(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
Row inputRow = KuduTestBase.booksDataRow().get(0);
for (int i = 0; i < inputRow.getArity(); i++) {
@@ -43,7 +48,9 @@ public class RowOperationMapperTest extends AbstractOperationTest {
@Test
void testCorrectOperationInsert() {
- RowOperationMapper mapper = new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ RowOperationMapper mapper =
+ new RowOperationMapper(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
Row inputRow = KuduTestBase.booksDataRow().get(0);
List<Operation> operations = mapper.createOperations(inputRow, mockTable);
@@ -54,7 +61,9 @@ public class RowOperationMapperTest extends AbstractOperationTest {
@Test
void testCorrectOperationUpsert() {
- RowOperationMapper mapper = new RowOperationMapper(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.UPSERT);
+ RowOperationMapper mapper =
+ new RowOperationMapper(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.UPSERT);
Row inputRow = KuduTestBase.booksDataRow().get(0);
List<Operation> operations = mapper.createOperations(inputRow, mockTable);
diff --git a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOpertaionMapperTest.java b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOperationMapperTest.java
similarity index 77%
rename from flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOpertaionMapperTest.java
rename to flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOperationMapperTest.java
index a52b7c1..774d3ed 100644
--- a/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOpertaionMapperTest.java
+++ b/flink-connector-kudu/src/test/java/org/apache/flink/connectors/kudu/writer/TupleOperationMapperTest.java
@@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.flink.connectors.kudu.writer;
import org.apache.flink.api.java.tuple.Tuple5;
import org.apache.flink.connectors.kudu.connector.KuduTestBase;
import org.apache.flink.connectors.kudu.connector.writer.AbstractSingleOperationMapper;
import org.apache.flink.connectors.kudu.connector.writer.TupleOperationMapper;
+
import org.apache.kudu.client.Operation;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -29,12 +31,15 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
-public class TupleOpertaionMapperTest extends AbstractOperationTest {
+/** Tests for {@link TupleOperationMapper}. */
+public class TupleOperationMapperTest extends AbstractOperationTest {
@Test
void testGetField() {
TupleOperationMapper<Tuple5<Integer, String, String, Double, Integer>> mapper =
- new TupleOperationMapper<>(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
- Tuple5<Integer, String, String, Double, Integer> inputTuple = KuduTestBase.booksDataTuple().get(0);
+ new TupleOperationMapper<>(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ Tuple5<Integer, String, String, Double, Integer> inputTuple =
+ KuduTestBase.booksDataTuple().get(0);
for (int i = 0; i < inputTuple.getArity(); i++) {
Assertions.assertEquals(inputTuple.getField(i), mapper.getField(inputTuple, i));
@@ -44,8 +49,10 @@ public class TupleOpertaionMapperTest extends AbstractOperationTest {
@Test
void testCorrectOperationInsert() {
TupleOperationMapper<Tuple5<Integer, String, String, Double, Integer>> mapper =
- new TupleOperationMapper<>(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
- Tuple5<Integer, String, String, Double, Integer> inputTuple = KuduTestBase.booksDataTuple().get(0);
+ new TupleOperationMapper<>(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.INSERT);
+ Tuple5<Integer, String, String, Double, Integer> inputTuple =
+ KuduTestBase.booksDataTuple().get(0);
List<Operation> operations = mapper.createOperations(inputTuple, mockTable);
@@ -56,8 +63,10 @@ public class TupleOpertaionMapperTest extends AbstractOperationTest {
@Test
void testCorrectOperationUpsert() {
TupleOperationMapper<Tuple5<Integer, String, String, Double, Integer>> mapper =
- new TupleOperationMapper<>(KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.UPSERT);
- Tuple5<Integer, String, String, Double, Integer> inputTuple = KuduTestBase.booksDataTuple().get(0);
+ new TupleOperationMapper<>(
+ KuduTestBase.columns, AbstractSingleOperationMapper.KuduOperation.UPSERT);
+ Tuple5<Integer, String, String, Double, Integer> inputTuple =
+ KuduTestBase.booksDataTuple().get(0);
List<Operation> operations = mapper.createOperations(inputTuple, mockTable);