Vaddi Bharath
02/26/2024, 5:51 AMTilman Krokotsch
02/26/2024, 10:18 AMVaddi Bharath
02/26/2024, 10:30 AMString createTabelSql = "create table flink_table_5(\n" +
" ts BIGINT,\n" +
" uuid VARCHAR(40) PRIMARY KEY NOT ENFORCED,\n" +
" rider VARCHAR(20),\n" +
" driver VARCHAR(20),\n" +
" fare DOUBLE,\n" +
" city VARCHAR(20)\n" +
")\n" +
"PARTITIONED BY (`city`)\n" +
"WITH (\n" +
" 'connector' = 'hudi',\n" +
" 'path' = 'abfs://hudi@test1datalakestoragegen2.dfs.core.windows.net/hudi/bharath/flink_table_5',\n" +
" 'table.type' = 'MERGE_ON_READ'\n" +
");";
System.out.println("2");
tableEnv = FlinkEnvironmentSingleton.getTableEnv()
tableEnv.executeSql(createTabelSql);
case 2:---but if i am trying to use tableEnv inside the map funtion in flink it is not working as expected
public class Bharath extends RichMapFunction<String,String> {
private TableEnvironment tableEnv;
@Override
public void open(Configuration parameters) throws Exception {
tableEnv = FlinkEnvironmentSingleton.getTableEnv();
}
@Override
public String map(String value) throws Exception {
tableEnv.executeSql(value);
return "success";
}
the below is the singleton class which i am using
public class FlinkEnvironmentSingleton {
private static StreamExecutionEnvironment env;
private static TableEnvironment tableEnv;
private FlinkEnvironmentSingleton() {}
public static synchronized StreamExecutionEnvironment getEnv() {
if (env == null) {
Properties props = new Properties();
props.put(
"azure credentials"
);
Configuration conf = ConfigurationUtils.createConfiguration(props);
env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
// env.setParallelism(2);
env.setRuntimeMode(RuntimeExecutionMode.STREAMING);
}
return env;
}
public static synchronized TableEnvironment getTableEnv() {
EnvironmentSettings envSettings = EnvironmentSettings.newInstance().inStreamingMode().build();
if (tableEnv == null) {
tableEnv = StreamTableEnvironment.create(getEnv(),envSettings);
}
return tableEnv;
}
public static void execute(String value){
getTableEnv().executeSql(value);
}
in both case-1 and case-2 i am using the same singleton class for getting the tableEnv and trying to create and insert into same table.But in case-1 it is working but in case 2 it is not working and giving this error ("Could not execute CreateTable in path default_catalog.default_database.`flink_table_5`")Tilman Krokotsch
02/26/2024, 10:34 AMRichMapFunction and implement your use case with DataStream or use executeSql of the Table API, not both at the same time. You are not supposed to access any environment in your map as the map code is executed in a distributed fashion does not live on the same machine as the first code snippet.Vaddi Bharath
02/26/2024, 10:35 AMVaddi Bharath
02/26/2024, 10:37 AMTilman Krokotsch
02/26/2024, 10:39 AMNadine Farah
02/27/2024, 10:22 PM