|
19 | 19 | import java.sql.DatabaseMetaData; |
20 | 20 | import java.sql.ResultSet; |
21 | 21 | import java.sql.SQLException; |
22 | | -import javax.annotation.Nullable; |
23 | 22 | import org.apache.calcite.avatica.MetaImpl; |
24 | 23 | import org.apache.calcite.avatica.SqlType; |
25 | 24 | import org.apache.calcite.rel.type.RelDataType; |
|
28 | 27 | import org.apache.calcite.schema.Table; |
29 | 28 | import org.apache.calcite.sql.SqlDialect; |
30 | 29 | import org.apache.calcite.sql.type.SqlTypeFactoryImpl; |
31 | | -import org.apache.calcite.sql.type.SqlTypeName; |
32 | | -import org.apache.calcite.util.Util; |
33 | 30 | import traindb.adapter.TrainDBSqlDialect; |
34 | 31 | import traindb.common.TrainDBLogger; |
35 | 32 | import traindb.schema.TrainDBSchema; |
@@ -127,82 +124,4 @@ private RelDataType getProtoType(MetaImpl.MetaTable tableDef, DatabaseMetaData d |
127 | 124 | return builder.build(); |
128 | 125 | } |
129 | 126 |
|
130 | | - private static RelDataType sqlType(RelDataTypeFactory typeFactory, int dataType, |
131 | | - int precision, int scale, boolean nullable, |
132 | | - @Nullable String typeString) { |
133 | | - // Fall back to ANY if type is unknown |
134 | | - final SqlTypeName sqlTypeName = |
135 | | - Util.first(SqlTypeName.getNameForJdbcType(dataType), SqlTypeName.ANY); |
136 | | - switch (sqlTypeName) { |
137 | | - case ARRAY: |
138 | | - RelDataType component = null; |
139 | | - if (typeString != null && typeString.endsWith(" ARRAY")) { |
140 | | - // E.g. hsqldb gives "INTEGER ARRAY", so we deduce the component type |
141 | | - // "INTEGER". |
142 | | - final String remaining = typeString.substring(0, |
143 | | - typeString.length() - " ARRAY".length()); |
144 | | - component = parseTypeString(typeFactory, remaining); |
145 | | - } |
146 | | - if (component == null) { |
147 | | - component = typeFactory.createTypeWithNullability( |
148 | | - typeFactory.createSqlType(SqlTypeName.ANY), true); |
149 | | - } |
150 | | - return typeFactory.createArrayType(component, -1); |
151 | | - case ANY: |
152 | | - if (typeString.startsWith("ST_")) { |
153 | | - return typeFactory.createTypeWithNullability( |
154 | | - typeFactory.createSqlType(SqlTypeName.GEOMETRY), nullable); |
155 | | - } |
156 | | - break; |
157 | | - default: |
158 | | - break; |
159 | | - } |
160 | | - if (precision >= 0 |
161 | | - && scale >= 0 |
162 | | - && sqlTypeName.allowsPrecScale(true, true)) { |
163 | | - return typeFactory.createSqlType(sqlTypeName, precision, scale); |
164 | | - } else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) { |
165 | | - return typeFactory.createSqlType(sqlTypeName, precision); |
166 | | - } else { |
167 | | - assert sqlTypeName.allowsNoPrecNoScale(); |
168 | | - return typeFactory.createSqlType(sqlTypeName); |
169 | | - } |
170 | | - } |
171 | | - |
172 | | - /** |
173 | | - * Given "INTEGER", returns BasicSqlType(INTEGER). |
174 | | - * Given "VARCHAR(10)", returns BasicSqlType(VARCHAR, 10). |
175 | | - * Given "NUMERIC(10, 2)", returns BasicSqlType(NUMERIC, 10, 2). |
176 | | - */ |
177 | | - private static RelDataType parseTypeString(RelDataTypeFactory typeFactory, |
178 | | - String typeString) { |
179 | | - int precision = -1; |
180 | | - int scale = -1; |
181 | | - int open = typeString.indexOf("("); |
182 | | - if (open >= 0) { |
183 | | - int close = typeString.indexOf(")", open); |
184 | | - if (close >= 0) { |
185 | | - String rest = typeString.substring(open + 1, close); |
186 | | - typeString = typeString.substring(0, open); |
187 | | - int comma = rest.indexOf(","); |
188 | | - if (comma >= 0) { |
189 | | - precision = Integer.parseInt(rest.substring(0, comma)); |
190 | | - scale = Integer.parseInt(rest.substring(comma)); |
191 | | - } else { |
192 | | - precision = Integer.parseInt(rest); |
193 | | - } |
194 | | - } |
195 | | - } |
196 | | - try { |
197 | | - final SqlTypeName typeName = SqlTypeName.valueOf(typeString); |
198 | | - return typeName.allowsPrecScale(true, true) |
199 | | - ? typeFactory.createSqlType(typeName, precision, scale) |
200 | | - : typeName.allowsPrecScale(true, false) |
201 | | - ? typeFactory.createSqlType(typeName, precision) |
202 | | - : typeFactory.createSqlType(typeName); |
203 | | - } catch (IllegalArgumentException e) { |
204 | | - return typeFactory.createTypeWithNullability( |
205 | | - typeFactory.createSqlType(SqlTypeName.ANY), true); |
206 | | - } |
207 | | - } |
208 | 127 | } |
0 commit comments