OmniSciDB  04ee39c94c
tester.java
Go to the documentation of this file.
1 /*
2  * Cool MapD License
3  */
4 package com.mapd.calcite.planner;
5 
11 
12 import org.apache.calcite.plan.RelOptUtil;
13 import org.apache.calcite.rel.RelRoot;
14 import org.apache.calcite.schema.SchemaPlus;
15 import org.apache.calcite.sql.SqlNode;
16 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
17 import org.apache.calcite.sql.parser.SqlParseException;
18 import org.apache.calcite.tools.FrameworkConfig;
19 import org.apache.calcite.tools.Frameworks;
20 import org.apache.calcite.tools.Planner;
21 import org.apache.calcite.tools.RelConversionException;
22 import org.apache.calcite.tools.ValidationException;
23 import org.slf4j.LoggerFactory;
24 
25 import java.util.ArrayList;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 
33 public class tester {
34  final static org.slf4j.Logger MAPDLOGGER = LoggerFactory.getLogger(tester.class);
35 
36  public static void main(String[] args) {
37  final SqlStdOperatorTable stdOpTab = SqlStdOperatorTable.instance();
38  // SqlOperatorTable opTab =
39  // ChainedSqlOperatorTable.of(stdOpTab,
40  // new ListSqlOperatorTable(
41  // ImmutableList.<SqlOperator>of(new MyCountAggFunction())));
42  MapDUser mdu = new MapDUser("admin", "passwd", "catalog", -1);
44  new MapDSchema("/home/michael/mapd2/build/data", null, -1, mdu, null);
45  final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
46  final FrameworkConfig config = Frameworks.newConfigBuilder()
47  .defaultSchema(rootSchema.add("omnisci", mapd))
48  .operatorTable(stdOpTab)
49  .build();
50 
51  Planner p = Frameworks.getPlanner(config);
52 
53  SqlNode parseR = null;
54  try {
55  parseR = p.parse("select * from customer where c_custkey = 1.345000 limit 5");
56  } catch (SqlParseException ex) {
57  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
58  }
59 
60  SqlNode validateR = null;
61  try {
62  p.validate(parseR);
63  } catch (ValidationException ex) {
64  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
65  }
66  RelRoot relR = null;
67  try {
68  relR = p.rel(validateR);
69  } catch (RelConversionException ex) {
70  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
71  }
72  MAPDLOGGER.error("Result was " + relR);
73  MAPDLOGGER.error("Result project() " + relR.project());
74  MAPDLOGGER.error("Result project() " + RelOptUtil.toString(relR.project()));
75  MAPDLOGGER.error("Json Version \n" + MapDSerializer.toString(relR.project()));
76 
77  // now do with MapD parser
78  MapDParser mp = new MapDParser("/home/michael/mapd2/build/data", null, -1, null);
79  mp.setUser(mdu);
80 
81  try {
83  MAPDLOGGER.error("MapDParser result: \n"
84  + mp.getRelAlgebra(
85  "select * from customer where c_custkey = 1.345000 limit 5",
86  mdpo,
87  mdu));
88  } catch (SqlParseException ex) {
89  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
90  } catch (ValidationException ex) {
91  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
92  } catch (RelConversionException ex) {
93  Logger.getLogger(tester.class.getName()).log(Level.SEVERE, null, ex);
94  }
95  }
96 
97  // /** User-defined aggregate function. */
98  // public static class MyCountAggFunction extends SqlAggFunction {
99  // public MyCountAggFunction() {
100  // super("MY_COUNT", null, SqlKind.OTHER_FUNCTION, ReturnTypes.BIGINT, null,
101  // OperandTypes.ANY, SqlFunctionCategory.NUMERIC, false, false);
102  // }
103  //
104  // @SuppressWarnings("deprecation")
105  // public List<RelDataType> getParameterTypes(RelDataTypeFactory typeFactory) {
106  // return ImmutableList.of(typeFactory.createSqlType(SqlTypeName.ANY));
107  // }
108  //
109  // @SuppressWarnings("deprecation")
110  // public RelDataType getReturnType(RelDataTypeFactory typeFactory) {
111  // return typeFactory.createSqlType(SqlTypeName.BIGINT);
112  // }
113  //
114  // public RelDataType deriveType(SqlValidator validator,
115  // SqlValidatorScope scope, SqlCall call) {
116  // // Check for COUNT(*) function. If it is we don't
117  // // want to try and derive the "*"
118  // if (call.isCountStar()) {
119  // return validator.getTypeFactory().createSqlType(SqlTypeName.BIGINT);
120  // }
121  // return super.deriveType(validator, scope, call);
122  // }
123  // }
124 }
static String toString(final RelNode rel)
static void main(String[] args)
Definition: tester.java:36
Definition: DataGen.cpp:60
static final org.slf4j.Logger MAPDLOGGER
Definition: tester.java:34
void setUser(MapDUser mapdUser)
String getRelAlgebra(String sql, final MapDParserOptions parserOptions, final MapDUser mapDUser)