Hi all, i have created env and table env as single...
# troubleshooting
v
Hi all, i have created env and table env as singleton class and trying to get and use them. 1)If i am getting and using outside the map funtion it is working as normal. 2)tableEnv or env is not working as expected inside the map.what may be the reason?or is there any way to do that? please some one reply me.
t
Your question is unclear. Could you provide a code sample of what you are trying to achieve and any error message you encounter?
v
Hello Tilman, Thanks for responding. case 1:---Basically i am trying to use tableEnv to execute the query(the blow code snippet is outside the map function in flink.)
Copy code
String 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
Copy code
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
Copy code
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`")
t
You are trying to mix Table API and DataStream API in a way that they are not supposed to. You can either use the
RichMapFunction
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.
v
Thank you for responding
If you know can you suggest some alternatives for hoodie-pipeline-builder in flink to insert into the hoodie?
t
I am not using it myself, so I can only point you to the documentation of Hudi, sorry.
n
following up- pinging @Danny Chen who is a pmc for flink and hudi