OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tester.java
Go to the documentation of this file.
1 /*
2  * Cool MapD License
3  */
4 package com.mapd.calcite.planner;
5 
12 
13 import org.apache.calcite.avatica.util.Casing;
14 import org.apache.calcite.plan.RelOptUtil;
15 import org.apache.calcite.rel.RelRoot;
16 import org.apache.calcite.schema.SchemaPlus;
17 import org.apache.calcite.sql.SqlNode;
18 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
19 import org.apache.calcite.sql.parser.SqlParseException;
20 import org.apache.calcite.sql.parser.SqlParser;
21 import org.apache.calcite.sql.validate.SqlConformanceEnum;
22 import org.apache.calcite.tools.FrameworkConfig;
23 import org.apache.calcite.tools.Frameworks;
24 import org.apache.calcite.tools.Planner;
25 import org.apache.calcite.tools.RelConversionException;
26 import org.apache.calcite.tools.ValidationException;
27 import org.slf4j.LoggerFactory;
28 
29 import java.util.function.Supplier;
30 import java.util.logging.Level;
31 import java.util.logging.Logger;
32 
37 public class tester {
38  final static org.slf4j.Logger MAPDLOGGER = LoggerFactory.getLogger(tester.class);
39 
40  public static void main(String[] args) {
41  final SqlStdOperatorTable stdOpTab = SqlStdOperatorTable.instance();
42 
43  MapDUser mdu = new MapDUser("admin", "passwd", "omnisci", -1, null);
44  MapDSchema mapd = new MapDSchema("<<PATH_TO_DATA_DIR>>", null, -1, mdu, null);
45  final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
46  final FrameworkConfig config =
47  Frameworks.newConfigBuilder()
48  .defaultSchema(rootSchema.add("omnisci", mapd))
49  .operatorTable(stdOpTab)
50  .parserConfig(SqlParser.configBuilder()
51  .setConformance(SqlConformanceEnum.LENIENT)
52  .setUnquotedCasing(Casing.UNCHANGED)
53  .setCaseSensitive(false)
54  .build())
55  .build();
56 
57  Planner p = Frameworks.getPlanner(config);
58 
59  SqlNode parseR = null;
60  try {
61  parseR = p.parse("<<QUERY>>");
62  } catch (SqlParseException ex) {
63  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
64  }
65 
66  SqlNode validateR = null;
67  try {
68  p.validate(parseR);
69  } catch (ValidationException ex) {
70  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
71  }
72  RelRoot relR = null;
73  try {
74  relR = p.rel(validateR);
75  } catch (RelConversionException ex) {
76  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
77  }
78  MAPDLOGGER.error("Result was " + relR);
79  MAPDLOGGER.error("Result project() " + relR.project());
80  MAPDLOGGER.error("Result project() " + RelOptUtil.toString(relR.project()));
81  MAPDLOGGER.error("Json Version \n" + MapDSerializer.toString(relR.project()));
82 
83  // now do with MapD parser
84  Supplier<MapDSqlOperatorTable> operatorTable = new Supplier<MapDSqlOperatorTable>() {
85  @Override
86  public MapDSqlOperatorTable get() {
87  return new MapDSqlOperatorTable(SqlStdOperatorTable.instance());
88  }
89  };
90  MapDParser mp = new MapDParser("<<PATH_TO_DATA_DIR>>", operatorTable, -1, null);
91  mp.setUser(mdu);
92 
93  try {
95  MAPDLOGGER.error("MapDParser result: \n" + mp.processSql("<<QUERY>>", mdpo));
96  } catch (SqlParseException ex) {
97  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
98  } catch (ValidationException ex) {
99  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
100  } catch (RelConversionException ex) {
101  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
102  }
103  }
104 
105  // /** User-defined aggregate function. */
106  // public static class MyCountAggFunction extends SqlAggFunction {
107  // public MyCountAggFunction() {
108  // super("MY_COUNT", null, SqlKind.OTHER_FUNCTION, ReturnTypes.BIGINT, null,
109  // OperandTypes.ANY, SqlFunctionCategory.NUMERIC, false, false);
110  // }
111  //
112  // @SuppressWarnings("deprecation")
113  // public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
114  // return ImmutableList.of(typeFactory.createSqlType(SqlTypeName.ANY));
115  // }
116  //
117  // @SuppressWarnings("deprecation")
118  // public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
119  // return typeFactory.createSqlType(SqlTypeName.BIGINT);
120  // }
121  //
122  // public RelDataType deriveType(SqlValidator validator,
123  // SqlValidatorScope scope, SqlCall call) {
124  // // Check for COUNT(*) function. If it is we don't
125  // // want to try and derive the "*"
126  // if (call.isCountStar()) {
127  // return validator.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
128  // }
129  // return super.deriveType(validator, scope, call);
130  // }
131  // }
132 }
static void main(String[] args)
Definition: tester.java:40
static final org.slf4j.Logger MAPDLOGGER
Definition: tester.java:38