Skip to content

Commit

Permalink
Feat: TRAIN MODEL/CREATE SYNOPSIS with geometry types
Browse files Browse the repository at this point in the history
  • Loading branch information
taewhi committed Aug 9, 2024
1 parent d802a3d commit 5cc494b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
15 changes: 12 additions & 3 deletions traindb-core/src/main/java/traindb/engine/TrainDBQueryEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import traindb.schema.TrainDBTable;
import traindb.sql.TrainDBSqlCommand;
import traindb.sql.TrainDBSqlRunner;
import traindb.sql.TrainDBSqlUtil;
import traindb.task.TaskTracer;
import traindb.util.ZipUtils;

Expand Down Expand Up @@ -405,7 +406,7 @@ private void createSynopsisTable(String synopsisName, String schemaName, String
throw new TrainDBException("cannot find base column information");
}
sb.append(columnName).append(" ");
SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(mColumn.getColumnType());
SqlTypeName sqlTypeName = TrainDBSqlUtil.getSqlTypeNameForJdbcType(mColumn.getColumnType());
switch (sqlTypeName) {
case CHAR:
case VARCHAR:
Expand Down Expand Up @@ -521,7 +522,13 @@ private void loadSynopsisIntoTable(String synopsisName, String schemaName, List<
sb.append(synopsisName);
sb.append(" VALUES (");
for (String columnName : columns) {
sb.append("?,");
MColumn mColumn = mTable.getColumn(columnName);
SqlTypeName sqlTypeName = TrainDBSqlUtil.getSqlTypeNameForJdbcType(mColumn.getColumnType());
if (sqlTypeName == SqlTypeName.GEOMETRY) {
sb.append("ST_GEOMFROMTEXT(?,0),");
} else {
sb.append("?,");
}
}
sb.deleteCharAt(sb.lastIndexOf(","));
sb.append(")");
Expand All @@ -542,7 +549,8 @@ private void loadSynopsisIntoTable(String synopsisName, String schemaName, List<
if (mColumn == null) {
throw new TrainDBException("cannot find base column information");
}
SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(mColumn.getColumnType());
SqlTypeName sqlTypeName =
TrainDBSqlUtil.getSqlTypeNameForJdbcType(mColumn.getColumnType());
switch (sqlTypeName) {
case INTEGER:
case TINYINT:
Expand All @@ -564,6 +572,7 @@ private void loadSynopsisIntoTable(String synopsisName, String schemaName, List<
break;
case CHAR:
case VARCHAR:
case GEOMETRY:
pstmt.setString(i, row[i - 1]);
break;
case DATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import traindb.catalog.pm.MTable;
import traindb.catalog.pm.MTableExt;
import traindb.common.TrainDBLogger;
import traindb.sql.TrainDBSqlUtil;

public class TrainDBCatalogSchema extends TrainDBSchema {
private static TrainDBLogger LOG = TrainDBLogger.getLogger(TrainDBCatalogSchema.class);
Expand Down Expand Up @@ -76,7 +77,7 @@ private RelDataType getProtoType(MTable mTable) {
RelDataType sqlType =
sqlType(typeFactory, mColumn.getColumnType(),
mColumn.getPrecision(), mColumn.getScale(), mColumn.isNullable(),
SqlTypeName.getNameForJdbcType(mColumn.getColumnType()).getName());
TrainDBSqlUtil.getSqlTypeNameForJdbcType(mColumn.getColumnType()).getName());

builder.add(mColumn.getColumnName(), sqlType);
}
Expand Down
29 changes: 29 additions & 0 deletions traindb-core/src/main/java/traindb/sql/TrainDBSqlUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package traindb.sql;

import org.apache.calcite.sql.type.ExtraSqlTypes;
import org.apache.calcite.sql.type.SqlTypeName;

public class TrainDBSqlUtil {

public static SqlTypeName getSqlTypeNameForJdbcType(int jdbcType) {
if (jdbcType == ExtraSqlTypes.GEOMETRY) {
return SqlTypeName.GEOMETRY;
}
return SqlTypeName.getNameForJdbcType(jdbcType);
}

}

0 comments on commit 5cc494b

Please sign in to comment.