From f26adefc85a45f1046a3eecc2700d1495dfb5f2f Mon Sep 17 00:00:00 2001 From: ajay-kharat Date: Thu, 13 Feb 2025 15:08:08 +0530 Subject: [PATCH] added hive and iceberg view test case --- .../facebook/presto/hive/TestHiveView.java | 90 ++++++++++++++++++ .../presto/iceberg/TestIcebergView.java | 93 +++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 presto-hive/src/test/java/com/facebook/presto/hive/TestHiveView.java create mode 100644 presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergView.java diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveView.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveView.java new file mode 100644 index 000000000000..efc7cb289228 --- /dev/null +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveView.java @@ -0,0 +1,90 @@ +/* + * 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 com.facebook.presto.hive; + +import com.facebook.presto.testing.QueryRunner; +import com.facebook.presto.tests.AbstractTestQueryFramework; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.testng.Assert.assertEquals; + +@Test(singleThreaded = true) +public class TestHiveView + extends AbstractTestQueryFramework +{ + @Override + protected QueryRunner createQueryRunner() throws Exception + { + return HiveQueryRunner.createQueryRunner(); + } + + @BeforeClass + public void setUp() + { + // Create Schema if not exists + getQueryRunner().execute("CREATE SCHEMA IF NOT EXISTS hive.dbcert_hive"); + } + + @AfterClass(alwaysRun = true) + public void tearDown() + { + getQueryRunner().execute("DROP VIEW IF EXISTS hive.dbcert_hive.vuuid"); + // Drop the schema if it's empty + List tables = getQueryRunner().execute( + "SHOW TABLES IN hive.dbcert_hive" + ).getMaterializedRows().stream() + .map(row -> row.getField(0)) + .collect(Collectors.toList()); + + if (tables.isEmpty()) { + getQueryRunner().execute("DROP SCHEMA IF EXISTS hive.dbcert_hive"); + } + } + + @Test + public void testHiveViewCreation() + { + // Create View with UUID in Hive + getQueryRunner().execute("CREATE OR REPLACE VIEW hive.dbcert_hive.vuuid AS " + + "SELECT * FROM ( " + + "VALUES (CAST(0 AS INTEGER), NULL), " + + "(CAST(1 AS INTEGER), UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59') " + + ") AS t (rum, c1)"); + + // Verify View Creation + List result = getQueryRunner().execute( + "SHOW TABLES IN hive.dbcert_hive LIKE 'vuuid'" + ).getMaterializedRows().stream() + .map(row -> row.getField(0)) + .collect(Collectors.toList()); + + assertEquals("vuuid", result.get(0).toString()); + } + + @Test(dependsOnMethods = "testHiveViewCreation") + public void testHiveViewSelect() + { + // Verify Select from View + Object result = getQueryRunner().execute( + "SELECT c1 FROM hive.dbcert_hive.vuuid WHERE rum = 1" + ).getOnlyValue(); + + assertEquals("12151fd2-7586-11e9-8f9e-2a86e4085a59", result.toString()); + } +} diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergView.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergView.java new file mode 100644 index 000000000000..ca47305d540b --- /dev/null +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergView.java @@ -0,0 +1,93 @@ +/* + * 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 com.facebook.presto.iceberg; + +import com.facebook.presto.testing.QueryRunner; +import com.facebook.presto.tests.AbstractTestQueryFramework; +import com.google.common.collect.ImmutableMap; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.stream.Collectors; + +import static com.facebook.presto.iceberg.IcebergQueryRunner.createIcebergQueryRunner; +import static org.testng.Assert.assertEquals; + +@Test(singleThreaded = true) +public class TestIcebergView + extends AbstractTestQueryFramework +{ + @Override + protected QueryRunner createQueryRunner() + throws Exception + { + return createIcebergQueryRunner(ImmutableMap.of("experimental.pushdown-subfields-enabled", "true"), ImmutableMap.of()); + } + + @BeforeClass + public void setUp() + { + // Create Schema if not exists + getQueryRunner().execute("CREATE SCHEMA IF NOT EXISTS iceberg.dbcert_iceberg"); + } + + @AfterClass(alwaysRun = true) + public void tearDown() + { + getQueryRunner().execute("DROP VIEW IF EXISTS iceberg.dbcert_iceberg.vuuid"); + // Drop the schema if it's empty + List tables = getQueryRunner().execute( + "SHOW TABLES IN iceberg.dbcert_iceberg" + ).getMaterializedRows().stream() + .map(row -> row.getField(0)) + .collect(Collectors.toList()); + + if (tables.isEmpty()) { + getQueryRunner().execute("DROP SCHEMA IF EXISTS iceberg.dbcert_iceberg"); + } + } + + @Test + public void testIcebergViewCreation() + { + // Create View with UUID in Iceberg + getQueryRunner().execute("CREATE OR REPLACE VIEW iceberg.dbcert_iceberg.vuuid AS " + + "SELECT * FROM ( " + + "VALUES (CAST(0 AS INTEGER), NULL), " + + "(CAST(1 AS INTEGER), UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59') " + + ") AS t (rum, c1)"); + + // Verify View Creation + List result = getQueryRunner().execute( + "SHOW TABLES IN iceberg.dbcert_iceberg LIKE 'vuuid'" + ).getMaterializedRows().stream() + .map(row -> row.getField(0)) + .collect(Collectors.toList()); + + assertEquals("vuuid", result.get(0).toString()); + } + + @Test(dependsOnMethods = "testIcebergViewCreation") + public void testIcebergViewSelect() + { + // Verify Select from View + Object result = getQueryRunner().execute( + "SELECT c1 FROM iceberg.dbcert_iceberg.vuuid WHERE rum = 1" + ).getOnlyValue(); + + assertEquals("12151fd2-7586-11e9-8f9e-2a86e4085a59", result.toString()); + } +}