|
16 | 16 |
|
17 | 17 | import java.nio.file.Path;
|
18 | 18 | import java.nio.file.Paths;
|
| 19 | +import java.sql.DatabaseMetaData; |
| 20 | +import java.sql.ResultSet; |
| 21 | +import java.sql.SQLException; |
19 | 22 | import java.util.List;
|
20 | 23 | import java.util.Map;
|
21 | 24 | import org.apache.calcite.adapter.java.JavaTypeFactory;
|
@@ -113,6 +116,11 @@ protected JSONObject buildTableMetadata(
|
113 | 116 | ('id', None): 'int',
|
114 | 117 | ('id', 'integer'): 'int',
|
115 | 118 | ('id', 'string'): 'str'
|
| 119 | +
|
| 120 | + // geometry types |
| 121 | + ('geometry', 'point'): 'point', |
| 122 | + ('geometry', 'linestring'): 'linestring', |
| 123 | + ('geometry', 'polygon'): 'polygon' |
116 | 124 | */
|
117 | 125 | switch (field.getType().getSqlTypeName()) {
|
118 | 126 | case CHAR:
|
@@ -142,6 +150,21 @@ protected JSONObject buildTableMetadata(
|
142 | 150 | case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
|
143 | 151 | typeInfo.put("type", "datetime");
|
144 | 152 | break;
|
| 153 | + case GEOMETRY: { |
| 154 | + typeInfo.put("type", "geometry"); |
| 155 | + String subtype = "geometry"; |
| 156 | + try { |
| 157 | + DatabaseMetaData md = conn.getMetaData(); |
| 158 | + ResultSet rs = md.getColumns("traindb", schemaName, tableName, field.getName()); |
| 159 | + while (rs.next()) { |
| 160 | + subtype = rs.getString("TYPE_NAME"); |
| 161 | + } |
| 162 | + } catch (SQLException e) { |
| 163 | + // ignore |
| 164 | + } |
| 165 | + typeInfo.put("subtype", subtype.toLowerCase().replaceFirst("^st_", "")); |
| 166 | + break; |
| 167 | + } |
145 | 168 | default:
|
146 | 169 | typeInfo.put("type", "unknown");
|
147 | 170 | break;
|
|
0 commit comments