Skip to content

Commit

Permalink
iceberg 1.15 test
Browse files Browse the repository at this point in the history
  • Loading branch information
vernedeng committed Aug 16, 2023
1 parent 716cafa commit 71fc23f
Show file tree
Hide file tree
Showing 30 changed files with 3,954 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,4 @@ private void addToGroupExt(InlongGroupInfo groupInfo, String value) {
groupInfo.getExtList().removeIf(ext -> extInfo.getKeyName().equals(ext.getKeyName()));
groupInfo.getExtList().add(extInfo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
*/
public class IcebergConstant {

public static final String CONNECTOR_KEY = "connector";
public static final String CONNECTOR = "iceberg-inlong";
public static final String DATABASE_KEY = "catalog-database";
public static final String DEFAULT_DATABASE_KEY = "default-database";
public static final String TABLE_KEY = "catalog-table";
public static final String CATALOG_TYPE_KEY = "catalog-type";
public static final String CATALOG_NAME_KEY = "catalog-name";
public static final String URI_KEY = "uri";
public static final String WAREHOUSE_KEY = "warehouse";

public static final String TABLE_EXEC_ICEBERG_USE_FLIP27_SOURCE = "table.exec.iceberg.use-flip27-source";

/**
* Iceberg supported catalog type
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.inlong.sort.protocol.node.extract.DorisExtractNode;
import org.apache.inlong.sort.protocol.node.extract.FileSystemExtractNode;
import org.apache.inlong.sort.protocol.node.extract.HudiExtractNode;
import org.apache.inlong.sort.protocol.node.extract.IcebergExtracNode;
import org.apache.inlong.sort.protocol.node.extract.KafkaExtractNode;
import org.apache.inlong.sort.protocol.node.extract.MongoExtractNode;
import org.apache.inlong.sort.protocol.node.extract.MySqlExtractNode;
Expand Down Expand Up @@ -64,6 +65,7 @@
@JsonSubTypes.Type(value = RedisExtractNode.class, name = "redisExtract"),
@JsonSubTypes.Type(value = DorisExtractNode.class, name = "dorisExtract"),
@JsonSubTypes.Type(value = HudiExtractNode.class, name = "hudiExtract"),
@JsonSubTypes.Type(value = IcebergExtracNode.class, name = "icebergExtract"),
})
@Data
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.inlong.sort.protocol.node.extract.DorisExtractNode;
import org.apache.inlong.sort.protocol.node.extract.FileSystemExtractNode;
import org.apache.inlong.sort.protocol.node.extract.HudiExtractNode;
import org.apache.inlong.sort.protocol.node.extract.IcebergExtracNode;
import org.apache.inlong.sort.protocol.node.extract.KafkaExtractNode;
import org.apache.inlong.sort.protocol.node.extract.MongoExtractNode;
import org.apache.inlong.sort.protocol.node.extract.MySqlExtractNode;
Expand Down Expand Up @@ -78,6 +79,7 @@
@JsonSubTypes.Type(value = RedisExtractNode.class, name = "redisExtract"),
@JsonSubTypes.Type(value = DorisExtractNode.class, name = "dorisExtract"),
@JsonSubTypes.Type(value = HudiExtractNode.class, name = "hudiExtract"),
@JsonSubTypes.Type(value = IcebergExtracNode.class, name = "icebergExtract"),
@JsonSubTypes.Type(value = TransformNode.class, name = "baseTransform"),
@JsonSubTypes.Type(value = DistinctNode.class, name = "distinct"),
@JsonSubTypes.Type(value = KafkaLoadNode.class, name = "kafkaLoad"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* 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.node.extract;

import org.apache.inlong.sort.protocol.FieldInfo;
import org.apache.inlong.sort.protocol.constant.IcebergConstant;
import org.apache.inlong.sort.protocol.node.ExtractNode;
import org.apache.inlong.sort.protocol.transformation.WatermarkField;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonTypeName;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
* Iceberg extract node for extract data from iceberg
*/
@EqualsAndHashCode(callSuper = true)
@JsonTypeName("icebergExtract")
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class IcebergExtracNode extends ExtractNode implements Serializable {

@JsonProperty("tableName")
@Nonnull
private String tableName;

@JsonProperty("dbName")
@Nonnull
private String dbName;

@JsonProperty("catalogType")
private IcebergConstant.CatalogType catalogType;

@Nullable
@JsonProperty("uri")
private String uri;

@JsonProperty("warehouse")
private String warehouse;

@JsonProperty("catalogName")
private String catalogName;

@JsonProperty("primaryKey")
private String primaryKey;

@JsonProperty("userFlip27")
private Boolean useFlip27;

public IcebergExtracNode(
@Nonnull @JsonProperty("id") String id,
@Nonnull @JsonProperty("name") String name,
@Nonnull @JsonProperty("fields") List<FieldInfo> fields,
@Nullable @JsonProperty("watermarkField") WatermarkField watermarkField,
@Nullable @JsonProperty("uri") String uri,
@Nullable @JsonProperty("warehouse") String warehouse,
@Nonnull @JsonProperty("dbName") String dbName,
@Nonnull @JsonProperty("tableName") String tableName,
@JsonProperty("catalogType") IcebergConstant.CatalogType catalogType,
@JsonProperty("catalogName") String catalogName,
@JsonProperty("primaryKey") String primaryKey,
@JsonProperty("userFlip27") Boolean userFlip27,
@Nullable @JsonProperty("properties") Map<String, String> properties) {
super(id, name, fields, watermarkField, properties);
this.uri = uri;
this.warehouse = warehouse;
this.dbName = dbName;
this.tableName = tableName;
this.catalogName = catalogName;
this.primaryKey = primaryKey;
this.useFlip27 = userFlip27;
this.catalogType = catalogType == null ? IcebergConstant.CatalogType.HIVE : catalogType;
}

@Override
public String genTableName() {
return String.format("iceberg_table_%s", getId());
}

@Override
public Map<String, String> tableOptions() {
Map<String, String> options = super.tableOptions();
options.put(IcebergConstant.CONNECTOR_KEY, IcebergConstant.CONNECTOR);
options.put(IcebergConstant.DATABASE_KEY, dbName);
options.put(IcebergConstant.TABLE_KEY, tableName);
options.put(IcebergConstant.CATALOG_TYPE_KEY, catalogType.name());
options.put(IcebergConstant.CATALOG_NAME_KEY, catalogName);
if (null != uri) {
options.put(IcebergConstant.URI_KEY, uri);
}
if (null != warehouse) {
options.put(IcebergConstant.WAREHOUSE_KEY, warehouse);
}
if (BooleanUtils.isTrue(useFlip27)) {
options.put(IcebergConstant.TABLE_EXEC_ICEBERG_USE_FLIP27_SOURCE, "true");
}
return options;
}

@Override
public String getPrimaryKey() {
return primaryKey;
}

@Override
public List<FieldInfo> getPartitionFields() {
return super.getPartitionFields();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ public IcebergLoadNode(@JsonProperty("id") String id,
@Override
public Map<String, String> tableOptions() {
Map<String, String> options = super.tableOptions();
options.put("connector", "iceberg-inlong");
options.put(IcebergConstant.CONNECTOR_KEY, IcebergConstant.CONNECTOR);
// for test sink.ignore.changelog
// options.put("sink.ignore.changelog", "true");
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());
options.put(IcebergConstant.DATABASE_KEY, dbName);
options.put(IcebergConstant.TABLE_KEY, tableName);
options.put(IcebergConstant.DEFAULT_DATABASE_KEY, dbName);
options.put(IcebergConstant.CATALOG_TYPE_KEY, catalogType.name());
options.put(IcebergConstant.CATALOG_NAME_KEY, catalogType.name());
if (null != uri) {
options.put("uri", uri);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* 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.parser;

import org.apache.inlong.sort.formats.common.LongFormatInfo;
import org.apache.inlong.sort.formats.common.StringFormatInfo;
import org.apache.inlong.sort.parser.impl.FlinkSqlParser;
import org.apache.inlong.sort.parser.result.FlinkSqlParseResult;
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;
import org.apache.inlong.sort.protocol.node.Node;
import org.apache.inlong.sort.protocol.node.extract.IcebergExtracNode;
import org.apache.inlong.sort.protocol.node.load.StarRocksLoadNode;
import org.apache.inlong.sort.protocol.transformation.FieldRelation;
import org.apache.inlong.sort.protocol.transformation.relation.NodeRelation;

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.test.util.AbstractTestBase;
import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Iceberg2StarRocksSqlParserTest extends AbstractTestBase {

private String groupId = "b_test_wk_0801";
private String streamId = "b_test_wkstream_0801";

private IcebergExtracNode buildIcebergExtracNode(String id) {
List<FieldInfo> fieldInfos = Arrays.asList(
new FieldInfo("id", new LongFormatInfo()),
new FieldInfo("name", new StringFormatInfo()),
new FieldInfo("source", new StringFormatInfo()),
new FieldInfo("count", new LongFormatInfo()),
new FieldInfo("remark", new StringFormatInfo()),
new FieldInfo("send_time", new StringFormatInfo()));
String uri = "thrift://ss-qe-nginx-tauth.tencent-distribute.com:9991";
String database = "test_inlong_iceberg";
String table = "t_ic_gwe0000000260d";
String catalogName = "HIVE";
String warehouse = "hdfs://qy-teg-2-v3/user/tdw/warehouse/test_inlong_iceberg.db/t_ic_gwe0000000260d";
return new IcebergExtracNode(id, "iceberg-source", fieldInfos, null, uri,
warehouse, database, table, IcebergConstant.CatalogType.HIVE, catalogName,
null, false, null);

}

private StarRocksLoadNode buildStarRocksLoadNode(String id) {
List<FieldInfo> fieldInfos = Arrays.asList(
new FieldInfo("id", new LongFormatInfo()),
new FieldInfo("name", new StringFormatInfo()),
new FieldInfo("source", new StringFormatInfo()),
new FieldInfo("count", new LongFormatInfo()),
new FieldInfo("remark", new StringFormatInfo()),
new FieldInfo("send_time", new StringFormatInfo()));
String user = "wedata";
String password = "wedata_admin";
String jdbc = "starrocks-teg-test-gz.polaris:9030";
String database = "wedata_dev";
String table = "table_400";
String primaryKey = "id";
String loadUrl = "11.160.103.19:8030";
List<FieldRelation> relations = Arrays
.asList(
new FieldRelation(new FieldInfo("id", new LongFormatInfo()),
new FieldInfo("id", new LongFormatInfo())),
new FieldRelation(new FieldInfo("name", new StringFormatInfo()),
new FieldInfo("name", new StringFormatInfo())),
new FieldRelation(new FieldInfo("source", new StringFormatInfo()),
new FieldInfo("source", new StringFormatInfo())));

Map<String, String> properties = new HashMap<>();
properties.put("sink.properties.format", "json");
properties.put("sink.properties.strip_outer_array", "true");
return new StarRocksLoadNode(id, "sink", fieldInfos, relations, null, null,
1, properties, jdbc, loadUrl, user, password, database,
table, primaryKey, null, null, null, null);
}

private NodeRelation buildNodeRelation(List<Node> inputs, List<Node> outputs) {
List<String> inputIds = inputs.stream().map(Node::getId).collect(Collectors.toList());
List<String> outputIds = outputs.stream().map(Node::getId).collect(Collectors.toList());
return new NodeRelation(inputIds, outputIds);
}

@Test
public void testIceberg() throws Exception {
EnvironmentSettings settings = EnvironmentSettings
.newInstance()
.inStreamingMode()
.build();
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env.setParallelism(1);
env.enableCheckpointing(10000);
StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings);
Node inputNode = buildIcebergExtracNode("1");
Node outputNode = buildStarRocksLoadNode("2");
StreamInfo streamInfo = new StreamInfo(streamId, Arrays.asList(inputNode, outputNode),
Arrays.asList(buildNodeRelation(Collections.singletonList(inputNode),
Collections.singletonList(outputNode))));
GroupInfo groupInfo = new GroupInfo(groupId, Collections.singletonList(streamInfo));

ObjectMapper objectMapper = new ObjectMapper();
System.out.println(objectMapper.writeValueAsString(groupInfo));
FlinkSqlParser parser = FlinkSqlParser.getInstance(tableEnv, groupInfo);
FlinkSqlParseResult result = (FlinkSqlParseResult) parser.parse();
Assert.assertTrue(!result.getLoadSqls().isEmpty() && !result.getCreateTableSqls().isEmpty());
}
}
3 changes: 2 additions & 1 deletion inlong-sort/sort-flink/sort-flink-v1.13/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<hudi.version>0.12.3</hudi.version>
<sqlserver.jdbc.version>7.2.2.jre8</sqlserver.jdbc.version>
<thrift.version>0.9.3</thrift.version>
<flink.iceberg.version>1.1.0</flink.iceberg.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -147,7 +148,7 @@
<dependency>
<groupId>org.apache.iceberg</groupId>
<artifactId>iceberg-flink-runtime-1.14</artifactId>
<version>${iceberg.version}</version>
<version>${flink.iceberg.version}</version>
</dependency>

<!-- flink -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<dependency>
<groupId>org.apache.iceberg</groupId>
<artifactId>iceberg-flink-runtime-1.14</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<module>jdbc</module>
<module>pulsar</module>

<module>iceberg</module>
<!--<module>iceberg</module>-->
<module>hbase</module>
<module>postgres-cdc</module>
<module>mongodb-cdc</module>
Expand Down
5 changes: 0 additions & 5 deletions inlong-sort/sort-flink/sort-flink-v1.15/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@
<artifactId>mssql-jdbc</artifactId>
<version>${sqlserver.jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.apache.iceberg</groupId>
<artifactId>iceberg-flink-runtime-1.14</artifactId>
<version>${iceberg.version}</version>
</dependency>

<!-- flink -->
<dependency>
Expand Down
Loading

0 comments on commit 71fc23f

Please sign in to comment.