Skip to content

Commit 4b7b4b3

Browse files
authored
Rewrite Geometry to Varchar type for verifier temp tables (prestodb#26140)
Summary: For queries being tested with verifier, if the output type is Geometry, the test case will be skipped due to a "NOT_SUPPORTED Type 'Geometry' cannot be written to a Hive table. Cast to a supported type such as VARCHAR or VARBINARY." error for both the control and test queries. This change rewrites the column type from Geometry to Varchar using the ST_AsText function, which is deterministic. Differential Revision: D83139143 ``` == NO RELEASE NOTE == ```
1 parent 1f99afc commit 4b7b4b3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

presto-verifier/src/main/java/com/facebook/presto/verifier/rewrite/QueryRewriter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.facebook.presto.sql.tree.DropTable;
3636
import com.facebook.presto.sql.tree.DropView;
3737
import com.facebook.presto.sql.tree.Expression;
38+
import com.facebook.presto.sql.tree.FunctionCall;
3839
import com.facebook.presto.sql.tree.Identifier;
3940
import com.facebook.presto.sql.tree.Insert;
4041
import com.facebook.presto.sql.tree.IsNullPredicate;
@@ -84,6 +85,7 @@
8485
import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
8586
import static com.facebook.presto.common.type.UnknownType.UNKNOWN;
8687
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
88+
import static com.facebook.presto.geospatial.type.GeometryType.GEOMETRY;
8789
import static com.facebook.presto.hive.HiveUtil.parsePartitionValue;
8890
import static com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionNamesAndValues;
8991
import static com.facebook.presto.sql.tree.LikeClause.PropertiesOption.INCLUDING;
@@ -424,9 +426,19 @@ private Query rewriteNonStorableColumns(Query query, ResultSetMetaData metadata)
424426
checkState(selectItems.size() == columnTypes.size(), "SelectItem count (%s) mismatches column count (%s)", selectItems.size(), columnTypes.size());
425427
for (int i = 0; i < selectItems.size(); i++) {
426428
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);
428431
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()));
430442
}
431443
else {
432444
newItems.add(singleColumn);
@@ -460,6 +472,9 @@ private Optional<Type> getColumnTypeRewrite(Type type)
460472
if (type.equals(UNKNOWN)) {
461473
return Optional.of(BIGINT);
462474
}
475+
if (type.equals(GEOMETRY)) {
476+
return Optional.of(VARCHAR);
477+
}
463478
if (type instanceof DecimalType) {
464479
return Optional.of(DOUBLE);
465480
}

0 commit comments

Comments
 (0)