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