OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CalciteParserFactory.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.parser.server;
17 
21 
22 import org.apache.calcite.sql.fun.SqlStdOperatorTable;
23 import org.apache.calcite.util.ConversionUtil;
24 import org.apache.commons.pool.PoolableObjectFactory;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 
28 import java.util.Map;
29 import java.util.function.Supplier;
30 
35 class CalciteParserFactory implements PoolableObjectFactory {
36  final static Logger MAPDLOGGER = LoggerFactory.getLogger(CalciteParserFactory.class);
37 
38  private final String dataDir;
39  private final Map<String, ExtensionFunction> extSigs;
40  private final int mapdPort;
43  private final Supplier<MapDSqlOperatorTable> tableOperatorSupplier =
44  new Supplier<MapDSqlOperatorTable>() {
45  @Override
46  public MapDSqlOperatorTable get() {
47  return tableOperator;
48  }
49  };
50 
51  static {
52  System.setProperty(
53  "saffron.default.charset", ConversionUtil.NATIVE_UTF16_CHARSET_NAME);
54  System.setProperty(
55  "saffron.default.nationalcharset", ConversionUtil.NATIVE_UTF16_CHARSET_NAME);
56  System.setProperty("saffron.default.collation.name",
57  ConversionUtil.NATIVE_UTF16_CHARSET_NAME + "$en_US");
58  }
59 
61  final Map<String, ExtensionFunction> extSigs,
62  int mapdPort,
64  this.dataDir = dataDir;
65  this.extSigs = extSigs;
66  this.mapdPort = mapdPort;
67  this.socket_transport_properties = skT;
68 
70  }
71 
72  public void updateOperatorTable() {
74  new MapDSqlOperatorTable(SqlStdOperatorTable.instance());
75  MapDSqlOperatorTable.addUDF(tableOperator, extSigs);
76  this.tableOperator = tableOperator;
77  }
78 
79  @Override
80  public Object makeObject() throws Exception {
81  MapDParser obj = new MapDParser(
83  return obj;
84  }
85 
86  @Override
87  public void destroyObject(Object obj) throws Exception {
88  // no need to do anything
89  }
90 
91  @Override
92  public boolean validateObject(Object obj) {
93  MapDParser mdp = (MapDParser) obj;
94  if (mdp.getCallCount() < 1000) {
95  return true;
96  } else {
97  MAPDLOGGER.debug(" invalidating object due to max use count");
98  return false;
99  }
100  }
101 
102  @Override
103  public void activateObject(Object obj) throws Exception {
104  // don't need to do anything
105  }
106 
107  @Override
108  public void passivateObject(Object obj) throws Exception {
109  // nothing to currently do here
110  }
111 }
CalciteParserFactory(String dataDir, final Map< String, ExtensionFunction > extSigs, int mapdPort, SockTransportProperties skT)
final Supplier< MapDSqlOperatorTable > tableOperatorSupplier
final Map< String, ExtensionFunction > extSigs
final SockTransportProperties socket_transport_properties