Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.facebook.presto.sql.tree.DropTable;
import com.facebook.presto.sql.tree.DropView;
import com.facebook.presto.sql.tree.Expression;
import com.facebook.presto.sql.tree.FunctionCall;
import com.facebook.presto.sql.tree.Identifier;
import com.facebook.presto.sql.tree.Insert;
import com.facebook.presto.sql.tree.IsNullPredicate;
Expand Down Expand Up @@ -84,6 +85,7 @@
import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static com.facebook.presto.common.type.UnknownType.UNKNOWN;
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
import static com.facebook.presto.geospatial.type.GeometryType.GEOMETRY;
import static com.facebook.presto.hive.HiveUtil.parsePartitionValue;
import static com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionNamesAndValues;
import static com.facebook.presto.sql.tree.LikeClause.PropertiesOption.INCLUDING;
Expand Down Expand Up @@ -424,9 +426,19 @@ private Query rewriteNonStorableColumns(Query query, ResultSetMetaData metadata)
checkState(selectItems.size() == columnTypes.size(), "SelectItem count (%s) mismatches column count (%s)", selectItems.size(), columnTypes.size());
for (int i = 0; i < selectItems.size(); i++) {
SingleColumn singleColumn = (SingleColumn) selectItems.get(i);
Optional<Type> columnTypeRewrite = getColumnTypeRewrite(columnTypes.get(i));
Type columnType = columnTypes.get(i);
Optional<Type> columnTypeRewrite = getColumnTypeRewrite(columnType);
if (columnTypeRewrite.isPresent()) {
newItems.add(new SingleColumn(new Cast(singleColumn.getExpression(), columnTypeRewrite.get().getTypeSignature().toString()), singleColumn.getAlias()));
Expression expression = singleColumn.getExpression();
if (columnType.equals(GEOMETRY)) {
// Geometry type not a Hive writable type, thus it should be converted to VARCHAR type in WKT
// format using the ST_AsText function.
expression = new FunctionCall(QualifiedName.of("ST_AsText"), ImmutableList.of(expression));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @HeidiHan0000 , are all Geometry values convertable to varchar, by ST_AsText? How about ST_AsBinary? Is it the case that either of the two works here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. St_astext returns WKT (Varchar) while st_asbinary returns the WKB format (Varbinary), and both are deterministic functions. @jagill Please let me know if you prefer to use the varbinary format with st_asbinary, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got confirmation from @Sullivan-Patrick that either will work. WKB will be more efficient, but WKT will be human readable

}
else {
expression = new Cast(expression, columnTypeRewrite.get().getTypeSignature().toString());
}
newItems.add(new SingleColumn(expression, singleColumn.getAlias()));
}
else {
newItems.add(singleColumn);
Expand Down Expand Up @@ -460,6 +472,9 @@ private Optional<Type> getColumnTypeRewrite(Type type)
if (type.equals(UNKNOWN)) {
return Optional.of(BIGINT);
}
if (type.equals(GEOMETRY)) {
return Optional.of(VARCHAR);
}
if (type instanceof DecimalType) {
return Optional.of(DOUBLE);
}
Expand Down
Loading