17 package com.mapd.calcite.parser;
23 import org.apache.calcite.config.CalciteConnectionConfig;
24 import org.apache.calcite.rel.type.RelDataType;
25 import org.apache.calcite.rel.type.RelDataTypeFactory;
26 import org.apache.calcite.schema.Schema;
27 import org.apache.calcite.schema.Statistic;
28 import org.apache.calcite.schema.Statistics;
29 import org.apache.calcite.schema.Table;
30 import org.apache.calcite.sql.SqlCall;
31 import org.apache.calcite.sql.SqlNode;
32 import org.apache.calcite.sql.type.SqlTypeName;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import java.util.HashSet;
37 import java.util.concurrent.atomic.AtomicLong;
38 import java.util.stream.Collectors;
40 import ai.heavy.thrift.server.TColumnType;
41 import ai.heavy.thrift.server.TDatumType;
42 import ai.heavy.thrift.server.TTableDetails;
43 import ai.heavy.thrift.server.TTypeInfo;
48 final static Logger
HEAVYDBLOGGER = LoggerFactory.getLogger(HeavyDBTable.class);
50 private final long version = VERSION_PROVIDER.incrementAndGet();
60 .filter(row_desc -> row_desc.is_system)
61 .map(row_desc -> row_desc.col_name)
62 .collect(Collectors.toCollection(HashSet::new));
67 RelDataTypeFactory.Builder builder = rdtf.builder();
68 for (TColumnType tct :
rowInfo.getRow_desc()) {
69 HEAVYDBLOGGER.debug(
"'" + tct.col_name +
"'"
70 +
" \t" + tct.getCol_type().getEncoding() +
" \t"
71 + tct.getCol_type().
getFieldValue(TTypeInfo._Fields.TYPE) +
" \t"
72 + tct.getCol_type().nullable +
" \t" + tct.getCol_type().is_array +
" \t"
73 + tct.getCol_type().precision +
" \t" + tct.getCol_type().scale);
74 builder.add(tct.col_name,
createType(tct, rdtf));
76 return builder.build();
81 return Statistics.UNKNOWN;
86 return Schema.TableType.TABLE;
89 private RelDataType
createType(TColumnType value, RelDataTypeFactory typeFactory) {
91 value.col_type.precision,
95 if (value.col_type.is_array) {
96 cType = typeFactory.createArrayType(
97 typeFactory.createTypeWithNullability(cType,
true), -1);
100 if (value.col_type.isNullable()) {
101 return typeFactory.createTypeWithNullability(cType,
true);
111 TDatumType dType,
int precision,
int scale, RelDataTypeFactory typeFactory) {
114 return typeFactory.createSqlType(SqlTypeName.TINYINT);
116 return typeFactory.createSqlType(SqlTypeName.SMALLINT);
118 return typeFactory.createSqlType(SqlTypeName.INTEGER);
120 return typeFactory.createSqlType(SqlTypeName.BIGINT);
122 return typeFactory.createSqlType(SqlTypeName.FLOAT);
124 return typeFactory.createSqlType(SqlTypeName.DECIMAL, precision, scale);
126 return typeFactory.createSqlType(SqlTypeName.DOUBLE);
128 return typeFactory.createSqlType(SqlTypeName.VARCHAR, 50);
130 return typeFactory.createSqlType(SqlTypeName.TIME);
132 return typeFactory.createSqlType(SqlTypeName.TIMESTAMP, precision);
134 return typeFactory.createSqlType(SqlTypeName.DATE);
136 return typeFactory.createSqlType(SqlTypeName.BOOLEAN);
137 case INTERVAL_DAY_TIME:
138 return typeFactory.createSqlType(SqlTypeName.INTERVAL_DAY);
139 case INTERVAL_YEAR_MONTH:
140 return typeFactory.createSqlType(SqlTypeName.INTERVAL_YEAR_MONTH);
142 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
145 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
148 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
150 case MULTILINESTRING:
151 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
154 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
157 return typeFactory.createSqlType(SqlTypeName.GEOMETRY);
160 throw new AssertionError(dType.name());
172 String
string, SqlCall sc, SqlNode sn, CalciteConnectionConfig ccc) {
173 throw new UnsupportedOperationException(
174 "rolledUpColumnValidInsideAgg Not supported yet.");
178 return systemColumnNames.contains(columnName);
RelDataType getRelDataType(TDatumType dType, int precision, int scale, RelDataTypeFactory typeFactory)
boolean rolledUpColumnValidInsideAgg(String string, SqlCall sc, SqlNode sn, CalciteConnectionConfig ccc)
final HashSet< String > systemColumnNames
RelDataType createType(TColumnType value, RelDataTypeFactory typeFactory)
static final Logger HEAVYDBLOGGER
static final AtomicLong VERSION_PROVIDER
void getFieldValue(T &result, TargetValue *field)
final TTableDetails rowInfo
RelDataType getRowType(RelDataTypeFactory rdtf)
boolean isRolledUp(String string)
Schema.TableType getJdbcTableType()
HeavyDBTable(TTableDetails ri)
boolean isSystemColumn(final String columnName)