|
35 | 35 | import com.facebook.presto.sql.tree.DropTable; |
36 | 36 | import com.facebook.presto.sql.tree.DropView; |
37 | 37 | import com.facebook.presto.sql.tree.Expression; |
| 38 | +import com.facebook.presto.sql.tree.FunctionCall; |
38 | 39 | import com.facebook.presto.sql.tree.Identifier; |
39 | 40 | import com.facebook.presto.sql.tree.Insert; |
40 | 41 | import com.facebook.presto.sql.tree.IsNullPredicate; |
|
84 | 85 | import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE; |
85 | 86 | import static com.facebook.presto.common.type.UnknownType.UNKNOWN; |
86 | 87 | import static com.facebook.presto.common.type.VarcharType.VARCHAR; |
| 88 | +import static com.facebook.presto.geospatial.type.GeometryType.GEOMETRY; |
87 | 89 | import static com.facebook.presto.hive.HiveUtil.parsePartitionValue; |
88 | 90 | import static com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionNamesAndValues; |
89 | 91 | import static com.facebook.presto.sql.tree.LikeClause.PropertiesOption.INCLUDING; |
@@ -424,9 +426,19 @@ private Query rewriteNonStorableColumns(Query query, ResultSetMetaData metadata) |
424 | 426 | checkState(selectItems.size() == columnTypes.size(), "SelectItem count (%s) mismatches column count (%s)", selectItems.size(), columnTypes.size()); |
425 | 427 | for (int i = 0; i < selectItems.size(); i++) { |
426 | 428 | SingleColumn singleColumn = (SingleColumn) selectItems.get(i); |
427 | | - Optional<Type> columnTypeRewrite = getColumnTypeRewrite(columnTypes.get(i)); |
| 429 | + Type columnType = columnTypes.get(i); |
| 430 | + Optional<Type> columnTypeRewrite = getColumnTypeRewrite(columnType); |
428 | 431 | if (columnTypeRewrite.isPresent()) { |
429 | | - newItems.add(new SingleColumn(new Cast(singleColumn.getExpression(), columnTypeRewrite.get().getTypeSignature().toString()), singleColumn.getAlias())); |
| 432 | + Expression expression = singleColumn.getExpression(); |
| 433 | + if (columnType.equals(GEOMETRY)) { |
| 434 | + // Geometry type not a Hive writable type, thus it should be converted to VARCHAR type in WKT |
| 435 | + // format using the ST_AsText function. |
| 436 | + expression = new FunctionCall(QualifiedName.of("ST_AsText"), ImmutableList.of(expression)); |
| 437 | + } |
| 438 | + else { |
| 439 | + expression = new Cast(expression, columnTypeRewrite.get().getTypeSignature().toString()); |
| 440 | + } |
| 441 | + newItems.add(new SingleColumn(expression, singleColumn.getAlias())); |
430 | 442 | } |
431 | 443 | else { |
432 | 444 | newItems.add(singleColumn); |
@@ -460,6 +472,9 @@ private Optional<Type> getColumnTypeRewrite(Type type) |
460 | 472 | if (type.equals(UNKNOWN)) { |
461 | 473 | return Optional.of(BIGINT); |
462 | 474 | } |
| 475 | + if (type.equals(GEOMETRY)) { |
| 476 | + return Optional.of(VARCHAR); |
| 477 | + } |
463 | 478 | if (type instanceof DecimalType) { |
464 | 479 | return Optional.of(DOUBLE); |
465 | 480 | } |
|
0 commit comments