Skip to content

Commit

Permalink
[Improve][Flink][core]The outdated method of creating a table is depr…
Browse files Browse the repository at this point in the history
…ecated
  • Loading branch information
zhilinli123 committed Jun 16, 2023
1 parent 580276a commit 66a2958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.seatunnel.core.starter.flink.utils.EnvironmentUtil;
import org.apache.seatunnel.core.starter.flink.utils.TableUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.configuration.Configuration;
Expand All @@ -44,6 +45,8 @@
import org.apache.flink.table.api.EnvironmentSettings;
import org.apache.flink.table.api.TableConfig;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.expressions.Expression;
import org.apache.flink.table.expressions.ExpressionParser;
import org.apache.flink.types.Row;
import org.apache.flink.util.TernaryBoolean;

Expand Down Expand Up @@ -320,9 +323,10 @@ public void registerResultTable(Config config, DataStream<Row> dataStream) {
if (!TableUtil.tableExists(tableEnvironment, name)) {
if (config.hasPath("field_name")) {
String fieldName = config.getString("field_name");
tableEnvironment.registerDataStream(name, dataStream, fieldName);
Expression[] expression = getExpression(fieldName);
tableEnvironment.createTemporaryView(name, dataStream, expression);
} else {
tableEnvironment.registerDataStream(name, dataStream);
tableEnvironment.createTemporaryView(name, dataStream);
}
}
}
Expand All @@ -338,4 +342,13 @@ public static FlinkRuntimeEnvironment getInstance(Config config) {
}
return INSTANCE;
}

public static Expression[] getExpression(String fieldNames) {
String[] fieldNameArray = StringUtils.split(fieldNames, ",");
Expression[] fieldsExpression = new Expression[fieldNameArray.length];
for (int i = 0; i < fieldNameArray.length; i++) {
fieldsExpression[i] = ExpressionParser.parseExpression(fieldNameArray[i]);
}
return fieldsExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void registerResultTable(Config config, DataStream<Row> dataStream) {
String fieldName = config.getString("field_name");
tableEnvironment.registerDataStream(name, dataStream, fieldName);
} else {
tableEnvironment.registerDataStream(name, dataStream);
tableEnvironment.createTemporaryView(name, dataStream);
}
}
}
Expand Down

0 comments on commit 66a2958

Please sign in to comment.