This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git
The following commit(s) were added to refs/heads/master by this push:
new d2b380a9b [INLONG-4303][Sort] Iceberg Load Node add required option
(#4304)
d2b380a9b is described below
commit d2b380a9b553dd88d001b97a5172bf12247f7a0d
Author: thexia <[email protected]>
AuthorDate: Mon May 23 21:37:54 2022 +0800
[INLONG-4303][Sort] Iceberg Load Node add required option (#4304)
---
.../sort/protocol/constant/IcebergConstant.java | 42 +++++++++++++++++++
.../sort/protocol/node/load/IcebergLoadNode.java | 36 +++++++++++++++--
.../sort/parser/IcebergNodeSqlParserTest.java | 47 ++++++++++++++--------
3 files changed, 106 insertions(+), 19 deletions(-)
diff --git
a/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/constant/IcebergConstant.java
b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/constant/IcebergConstant.java
new file mode 100644
index 000000000..f846febd9
--- /dev/null
+++
b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/constant/IcebergConstant.java
@@ -0,0 +1,42 @@
+/*
+ * 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.inlong.sort.protocol.constant;
+
+/**
+ * Iceberg option constant
+ */
+public class IcebergConstant {
+ /**
+ * Iceberg supported catalog type
+ */
+ public enum CatalogType {
+ /**
+ * Data stored in hive metastore.
+ */
+ HIVE,
+ /**
+ * Data stored in hadoop filesystem.
+ */
+ HADOOP,
+ /**
+ * Data stored in hybris metastore.
+ */
+ HYBRIS
+ }
+}
diff --git
a/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/IcebergLoadNode.java
b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/IcebergLoadNode.java
index 460ee1251..2435a827a 100644
---
a/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/IcebergLoadNode.java
+++
b/inlong-sort/sort-common/src/main/java/org/apache/inlong/sort/protocol/node/load/IcebergLoadNode.java
@@ -26,6 +26,8 @@ import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCre
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
import
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeName;
import org.apache.inlong.sort.protocol.FieldInfo;
+import org.apache.inlong.sort.protocol.constant.IcebergConstant;
+import org.apache.inlong.sort.protocol.constant.IcebergConstant.CatalogType;
import org.apache.inlong.sort.protocol.enums.FilterStrategy;
import org.apache.inlong.sort.protocol.node.LoadNode;
import org.apache.inlong.sort.protocol.transformation.FieldRelationShip;
@@ -49,10 +51,22 @@ public class IcebergLoadNode extends LoadNode implements
Serializable {
@Nonnull
private String tableName;
- @JsonProperty("tableName")
+ @JsonProperty("dbName")
@Nonnull
private String dbName;
+ @JsonProperty("primaryKey")
+ private String primaryKey;
+
+ @JsonProperty("catalogType")
+ private IcebergConstant.CatalogType catalogType;
+
+ @JsonProperty("uri")
+ private String uri;
+
+ @JsonProperty("warehouse")
+ private String warehouse;
+
@JsonCreator
public IcebergLoadNode(@JsonProperty("id") String id,
@JsonProperty("name") String name,
@@ -63,10 +77,18 @@ public class IcebergLoadNode extends LoadNode implements
Serializable {
@Nullable @JsonProperty("sinkParallelism") Integer sinkParallelism,
@JsonProperty("properties") Map<String, String> properties,
@Nonnull @JsonProperty("dbName") String dbName,
- @Nonnull @JsonProperty("tableName") String tableName) {
+ @Nonnull @JsonProperty("tableName") String tableName,
+ @JsonProperty("primaryKey") String primaryKey,
+ @JsonProperty("catalogType") IcebergConstant.CatalogType
catalogType,
+ @JsonProperty("uri") String uri,
+ @JsonProperty("warehouse") String warehouse) {
super(id, name, fields, fieldRelationShips, filters, filterStrategy,
sinkParallelism, properties);
this.tableName = Preconditions.checkNotNull(tableName, "table name is
null");
this.dbName = Preconditions.checkNotNull(dbName, "db name is null");
+ this.primaryKey = primaryKey;
+ this.catalogType = catalogType == null ? CatalogType.HIVE :
catalogType;
+ this.uri = uri;
+ this.warehouse = warehouse;
}
@Override
@@ -76,6 +98,14 @@ public class IcebergLoadNode extends LoadNode implements
Serializable {
options.put("catalog-database", dbName);
options.put("catalog-table", tableName);
options.put("default-database", dbName);
+ options.put("catalog-type", catalogType.name());
+ options.put("catalog-name", catalogType.name());
+ if (null != uri) {
+ options.put("uri", uri);
+ }
+ if (null != warehouse) {
+ options.put("warehouse", warehouse);
+ }
return options;
}
@@ -86,7 +116,7 @@ public class IcebergLoadNode extends LoadNode implements
Serializable {
@Override
public String getPrimaryKey() {
- return super.getPrimaryKey();
+ return primaryKey;
}
@Override
diff --git
a/inlong-sort/sort-core/src/test/java/org/apache/inlong/sort/parser/IcebergNodeSqlParserTest.java
b/inlong-sort/sort-core/src/test/java/org/apache/inlong/sort/parser/IcebergNodeSqlParserTest.java
index fd12d735c..f59a5d397 100644
---
a/inlong-sort/sort-core/src/test/java/org/apache/inlong/sort/parser/IcebergNodeSqlParserTest.java
+++
b/inlong-sort/sort-core/src/test/java/org/apache/inlong/sort/parser/IcebergNodeSqlParserTest.java
@@ -32,6 +32,7 @@ import
org.apache.inlong.sort.formats.common.TimestampFormatInfo;
import org.apache.inlong.sort.protocol.FieldInfo;
import org.apache.inlong.sort.protocol.GroupInfo;
import org.apache.inlong.sort.protocol.StreamInfo;
+import org.apache.inlong.sort.protocol.constant.IcebergConstant.CatalogType;
import org.apache.inlong.sort.protocol.node.Node;
import org.apache.inlong.sort.protocol.node.extract.MySqlExtractNode;
import org.apache.inlong.sort.protocol.node.load.IcebergLoadNode;
@@ -85,13 +86,21 @@ public class IcebergNodeSqlParserTest extends
AbstractTestBase {
new FieldInfo("ts", new TimestampFormatInfo()))
);
- Map<String, String> props = new HashMap<>();
- props.put("catalog-type", "hadoop");
- props.put("catalog-name", "hadoop_prod");
- props.put("warehouse", "hdfs://localhost:9000/iceberg/warehouse");
- IcebergLoadNode node = new IcebergLoadNode("iceberg",
"iceberg_output", fields, relations,
- null, null, null, props, "inlong", "inlong_iceberg");
- return node;
+ return new IcebergLoadNode(
+ "iceberg",
+ "iceberg_output",
+ fields,
+ relations,
+ null,
+ null,
+ null,
+ null,
+ "inlong",
+ "inlong_iceberg",
+ null,
+ CatalogType.HADOOP,
+ null,
+ "hdfs://localhost:9000/iceberg/warehouse");
}
private IcebergLoadNode buildIcebergLoadNodeWithHiveCatalog() {
@@ -111,15 +120,21 @@ public class IcebergNodeSqlParserTest extends
AbstractTestBase {
);
// set HIVE_CONF_DIR,or set uri and warehouse
- Map<String, String> props = new HashMap<>();
- props.put("catalog-type", "hive");
- props.put("catalog-name", "hive_prod");
- props.put("catalog-database", "default");
- props.put("uri", "thrift://localhost:9083");
- props.put("warehouse", "/hive/warehouse");
- IcebergLoadNode node = new IcebergLoadNode("iceberg",
"iceberg_output", fields, relations,
- null, null, null, props, "inlong", "inlong_iceberg");
- return node;
+ return new IcebergLoadNode(
+ "iceberg",
+ "iceberg_output",
+ fields,
+ relations,
+ null,
+ null,
+ null,
+ null,
+ "inlong",
+ "inlong_iceberg",
+ null,
+ CatalogType.HIVE,
+ "thrift://localhost:9083",
+ "/hive/warehouse");
}
/**