Hi all !!! What is the significance or function of...
# troubleshooting
a
Hi all !!! What is the significance or function of org.apache.flink.table.api.dataview.DataView? How to implement this class ?🥹
d
You would not typically implement this class if using table api. Instead you would create a temporary table to effectively have material view.
its going to look something like this
Copy code
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.api.Table;

public class DataViewExample {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        // Assume we have a source of data, e.g., a Kafka stream
        tableEnv.executeSql(
            "CREATE TABLE kafkaSource (\n" +
            "  id INT,\n" +
            "  amount DOUBLE,\n" +
            "  proctime AS PROCTIME(),\n" +
            "  WATERMARK FOR proctime AS proctime - INTERVAL '5' SECOND\n" +
            ") WITH (\n" +
            "  'connector' = 'kafka',\n" +  // Example connector setup
            "...);"
        );

        // define a table based on the source
        Table rawTable = tableEnv.from("kafkaSource");

        // create a materialized view (conceptually a DataView) for total sales per hour
        tableEnv.createTemporaryView("totalSalesPerHour", 
            rawTable
            .groupBy(tableEnv.window(rawTable.proctime, "TUMBLE(proctime, INTERVAL '1' HOUR)"), rawTable.id)
            .select(rawTable.id, rawTable.amount.sum())
        );

        // query the materialized view
        Table result = tableEnv.sqlQuery("SELECT * FROM totalSalesPerHour");

        // to emit the results to another sink, convert the Table back to a DataStream/Dataset
        // this step is illustrative and may vary based on your use case
        tableEnv.toAppendStream(result, Row.class).print();

        env.execute("Flink DataView Example");
    }
}
tableEnv.createTemporaryView() is used instead of DataView because of abstraction level provided by Flink Table API. Its a logical transformation defined at a higher level and declarative manner.
The materialization of results is handled by Flink Table and SQL API and manages the optimization plan, execution, and materialization of intermediate results in the manner of DataView.
You can also switch between different types of operations, sources, sinks etc.
if you still need to know how its used internally by Flink APIs let us know.