17 package com.mapd.calcite.planner;
26 import org.apache.calcite.avatica.util.Casing;
27 import org.apache.calcite.plan.RelOptUtil;
28 import org.apache.calcite.rel.RelRoot;
29 import org.apache.calcite.schema.SchemaPlus;
30 import org.apache.calcite.sql.SqlNode;
31 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
32 import org.apache.calcite.sql.parser.SqlParseException;
33 import org.apache.calcite.sql.parser.SqlParser;
34 import org.apache.calcite.sql.validate.SqlConformanceEnum;
35 import org.apache.calcite.tools.FrameworkConfig;
36 import org.apache.calcite.tools.Frameworks;
37 import org.apache.calcite.tools.Planner;
38 import org.apache.calcite.tools.RelConversionException;
39 import org.apache.calcite.tools.ValidationException;
40 import org.slf4j.LoggerFactory;
42 import java.util.function.Supplier;
43 import java.util.logging.Level;
44 import java.util.logging.Logger;
47 final static org.slf4j.Logger
HEAVYDBLOGGER = LoggerFactory.getLogger(tester.class);
50 final SqlStdOperatorTable stdOpTab = SqlStdOperatorTable.instance();
54 new HeavyDBSchema(
"<<PATH_TO_DATA_DIR>>", null, -1, mdu, null, null);
55 final SchemaPlus rootSchema = Frameworks.createRootSchema(
true);
56 final FrameworkConfig config =
57 Frameworks.newConfigBuilder()
58 .defaultSchema(rootSchema.add(
"omnisci", dbSchema))
59 .operatorTable(stdOpTab)
60 .parserConfig(SqlParser.configBuilder()
61 .setConformance(SqlConformanceEnum.LENIENT)
62 .setUnquotedCasing(Casing.UNCHANGED)
63 .setCaseSensitive(
false)
67 Planner p = Frameworks.getPlanner(config);
69 SqlNode parseR = null;
71 parseR = p.parse(
"<<QUERY>>");
72 }
catch (SqlParseException ex) {
73 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
76 SqlNode validateR = null;
79 }
catch (ValidationException ex) {
80 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
84 relR = p.rel(validateR);
85 }
catch (RelConversionException ex) {
86 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
88 HEAVYDBLOGGER.error(
"Result was " + relR);
89 HEAVYDBLOGGER.error(
"Result project() " + relR.project());
90 HEAVYDBLOGGER.error(
"Result project() " + RelOptUtil.toString(relR.project()));
91 HEAVYDBLOGGER.error(
"Json Version \n" + HeavyDBSerializer.toString(relR.project()));
94 Supplier<HeavyDBSqlOperatorTable> operatorTable =
95 new Supplier<HeavyDBSqlOperatorTable>() {
106 HEAVYDBLOGGER.error(
"HeavyDBParser result: \n" + mp.processSql(
"<<QUERY>>", mdpo));
107 }
catch (SqlParseException ex) {
108 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
109 }
catch (ValidationException ex) {
110 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
111 }
catch (RelConversionException ex) {
112 Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
static final org.slf4j.Logger HEAVYDBLOGGER
static void main(String[] args)