Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed hive view uuid type parsing #24538

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
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 @@ -227,6 +227,9 @@ public static boolean isSupportedType(TypeInfo typeInfo)
public static HiveType valueOf(String hiveTypeName)
{
requireNonNull(hiveTypeName, "hiveTypeName is null");
if (hiveTypeName.equals(HIVE_UUID.getTypeInfo().getTypeName())) {
return HIVE_UUID;
}
return toHiveType(getTypeInfoFromTypeString(hiveTypeName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static com.facebook.presto.SystemSessionProperties.REMOVE_REDUNDANT_CAST_TO_VARCHAR_IN_JOIN;
import static com.facebook.presto.SystemSessionProperties.SHARDED_JOINS_STRATEGY;
import static com.facebook.presto.SystemSessionProperties.VERBOSE_OPTIMIZER_INFO_ENABLED;
import static com.facebook.presto.common.type.UuidType.UUID;
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
import static com.facebook.presto.connector.informationSchema.InformationSchemaMetadata.INFORMATION_SCHEMA;
import static com.facebook.presto.sql.tree.CreateView.Security.INVOKER;
Expand Down Expand Up @@ -1569,4 +1570,26 @@ private String sanitizePlan(String explain)
.replaceAll("\\[PlanNodeId (\\d+(?:,\\d+)*)\\]", "")
.replaceAll("Values => .*\n", "\n");
}

@Test
public void testViewWithUUID()
{
skipTestUnless(supportsViews());

@Language("SQL") String query = "SELECT * FROM (VALUES (CAST(0 AS INTEGER), NULL), (CAST(1 AS INTEGER), UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59')) AS t (rum, c1)";

// Create View with UUID type in Hive
assertQuerySucceeds("CREATE VIEW test_hive_view AS " + query);

// Select UUID from the view
MaterializedResult result = computeActual("SELECT c1 FROM test_hive_view WHERE rum = 1");

// Verify the result set is not empty
assertTrue(result.getMaterializedRows().size() > 0, "Result set is empty");
Copy link
Member

Choose a reason for hiding this comment

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

Can't we compare the UUID value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we cannot directly compare the UUID returned in the result unless casted to string.

Copy link
Member

Choose a reason for hiding this comment

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

As I see, the data maintained in materialized row for uuid is already plain string, so seems we can validate the result as follows:

assertEquals(result.getTypes(), ImmutableList.of(UUID));
assertEquals(result.getOnlyValue(), "12151fd2-7586-11e9-8f9e-2a86e4085a59");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, it worked.
Changes pushed to compare type and UUID returned in the result.

assertEquals(result.getTypes(), ImmutableList.of(UUID));
assertEquals(result.getOnlyValue(), "12151fd2-7586-11e9-8f9e-2a86e4085a59");

// Drop the view after the test
assertQuerySucceeds("DROP VIEW test_hive_view");
}
}
Loading