import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.table.api.bridge.java.internal.StreamTableEnvironmentImpl;
import org.apache.flink.table.delegation.Parser;
import org.apache.flink.table.operations.Operation;
import java.util.List;
public class SqlParserCheckJob {
public static void main(String[] args) throws Exception {
// set up the streaming execution environment
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
final StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);
Parser parserImpl = ((StreamTableEnvironmentImpl) tEnv).getParser();
List<Operation> s1 = parserImpl.parse("select 1");
s1.forEach(d -> System.out.println(d.asSummaryString()));
List<Operation> s2 = parserImpl.parse("select 'abc' ");
s2.forEach(d -> System.out.println(d.asSummaryString()));
// create some DataStream
DataStream<Tuple2<Long, String>> dataStream = env.fromElements(
Tuple2.of(12L, "Alice"),
Tuple2.of(0L, "Bob"));
tEnv.createTemporaryView(
"test",
dataStream,
Schema.newBuilder()
.column("f0", "BIGINT")
.column("f1", "STRING")
.build());
System.out.println(tEnv.explainSql("select * from test where f0 = 1"));
}
}