Skip to content

Commit

Permalink
added hive and iceberg view test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adkharat committed Feb 13, 2025
1 parent d5f9256 commit f26adef
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Object> 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<Object> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<Object> 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<Object> 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());
}
}

0 comments on commit f26adef

Please sign in to comment.