Search in sources :

Example 1 with SqlQueryManager

use of io.prestosql.execution.SqlQueryManager in project hetu-core by openlookeng.

the class TestCachedSqlQueryExecution method testRenamedTable.

@Test
public void testRenamedTable() throws Exception {
    setupWithExecutionPlanCacheEnabled(DEFAULT_SESSION);
    TestingMetadata metadata = new TestingMetadata();
    queryRunner.installPlugin(new TestPlugin(metadata));
    queryRunner.createCatalog("test", "test");
    SqlQueryManager manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    String query1 = "CREATE TABLE orders AS SELECT ORDERKEY, CUSTKEY, TOTALPRICE FROM tpch.tiny.orders";
    String query2 = "INSERT INTO orders SELECT * FROM orders";
    String query3 = "SELECT * FROM orders";
    Plan plan1 = getPlan(query1, manager);
    Plan plan2 = getPlan(query2, manager);
    Plan plan3 = getPlan(query3, manager);
    metadata.dropTable(DEFAULT_SESSION.toConnectorSession(), metadata.getTableHandle(DEFAULT_SESSION.toConnectorSession(), new SchemaTableName("default", "orders")));
    String query4 = "CREATE TABLE nation AS SELECT * FROM tpch.tiny.nation";
    // Create table again
    Plan plan4 = getPlan(query4, manager);
    // different table with the same name
    metadata.renameTable(DEFAULT_SESSION.toConnectorSession(), metadata.getTableHandle(DEFAULT_SESSION.toConnectorSession(), new SchemaTableName("default", "nation")), new SchemaTableName("default", "orders"));
    // Insert into new table
    Plan plan5 = getPlan(query2, manager);
    Plan plan6 = getPlan(query3, manager);
    assertNotNull(plan1);
    assertNotNull(plan2);
    assertNotNull(plan3);
    assertNotNull(plan4);
    assertNotNull(plan6);
    // Underlying table schema changed
    assertNotSame(plan2.getStatsAndCosts(), plan5.getStatsAndCosts());
    // new plan should not be the same as the old plan
    assertNotSame(plan3.getStatsAndCosts(), plan6.getStatsAndCosts());
}
Also used : TestingMetadata(io.prestosql.testing.TestingMetadata) Plan(io.prestosql.sql.planner.Plan) SqlQueryManager(io.prestosql.execution.SqlQueryManager) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 2 with SqlQueryManager

use of io.prestosql.execution.SqlQueryManager in project hetu-core by openlookeng.

the class TestCachedSqlQueryExecution method testAlterTable.

@Test
public void testAlterTable() throws Exception {
    setupWithExecutionPlanCacheEnabled(DEFAULT_SESSION);
    TestingMetadata metadata = new TestingMetadata();
    queryRunner.installPlugin(new TestPlugin(metadata));
    queryRunner.createCatalog("test", "test");
    SqlQueryManager manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    String query1 = "CREATE TABLE orders AS SELECT ORDERKEY, CUSTKEY, TOTALPRICE FROM tpch.tiny.orders";
    String query2 = "INSERT INTO orders SELECT * FROM orders";
    String query3 = "SELECT * FROM orders";
    Plan plan1 = getPlan(query1, manager);
    Plan plan2 = getPlan(query2, manager);
    Plan plan3 = getPlan(query3, manager);
    metadata.dropTable(DEFAULT_SESSION.toConnectorSession(), metadata.getTableHandle(DEFAULT_SESSION.toConnectorSession(), new SchemaTableName("default", "orders")));
    String query4 = "CREATE TABLE orders AS SELECT * FROM tpch.tiny.orders";
    // Create table again
    Plan plan4 = getPlan(query4, manager);
    // Insert into new table
    Plan plan5 = getPlan(query2, manager);
    Plan plan6 = getPlan(query3, manager);
    assertNotNull(plan1);
    assertNotNull(plan2);
    assertNotNull(plan3);
    assertNotNull(plan4);
    assertNotNull(plan6);
    // Schema changed
    assertNotSame(plan2.getStatsAndCosts(), plan5.getStatsAndCosts());
    // Schema changed
    assertNotSame(plan3.getStatsAndCosts(), plan6.getStatsAndCosts());
}
Also used : TestingMetadata(io.prestosql.testing.TestingMetadata) Plan(io.prestosql.sql.planner.Plan) SqlQueryManager(io.prestosql.execution.SqlQueryManager) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 3 with SqlQueryManager

use of io.prestosql.execution.SqlQueryManager in project hetu-core by openlookeng.

the class TestCachedSqlQueryExecution method testExecutionPlanCacheModifedSessionProperty.

@Test
public void testExecutionPlanCacheModifedSessionProperty() throws Exception {
    setupWithExecutionPlanCacheEnabled(TPCH_SESSION);
    SqlQueryManager manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    String testSql = "SELECT ORDERKEY, TOTALPRICE FROM orders";
    Plan plan1 = getPlan(testSql, manager);
    setupWithExecutionPlanCacheEnabled(DEFAULT_SESSION_WITH_CHANGED_PROPERTY);
    manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    Plan plan2 = getPlan(testSql, manager);
    assertNotSame(plan1.getStatsAndCosts(), plan2.getStatsAndCosts());
    Plan plan3 = getPlan(testSql, manager);
    assertSame(plan2.getStatsAndCosts(), plan3.getStatsAndCosts());
}
Also used : Plan(io.prestosql.sql.planner.Plan) SqlQueryManager(io.prestosql.execution.SqlQueryManager) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 4 with SqlQueryManager

use of io.prestosql.execution.SqlQueryManager in project hetu-core by openlookeng.

the class TestCachedSqlQueryExecution method testExecutionPlanCacheEnabledMixedQueries.

@Test
public void testExecutionPlanCacheEnabledMixedQueries() throws Exception {
    setupWithExecutionPlanCacheEnabled(TPCH_SESSION);
    SqlQueryManager manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    String query = "EXPLAIN SELECT * FROM orders";
    Plan plan1 = getPlan(TEST_SQL, manager);
    Plan plan2 = getPlan(query, manager);
    Plan plan3 = getPlan(TEST_SQL, manager);
    Plan plan4 = getPlan(TEST_SQL, manager);
    assertNotSame(plan1.getStatsAndCosts(), plan2.getStatsAndCosts());
    assertSame(plan1.getStatsAndCosts(), plan3.getStatsAndCosts());
    assertSame(plan3.getStatsAndCosts(), plan4.getStatsAndCosts());
}
Also used : Plan(io.prestosql.sql.planner.Plan) SqlQueryManager(io.prestosql.execution.SqlQueryManager) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Example 5 with SqlQueryManager

use of io.prestosql.execution.SqlQueryManager in project hetu-core by openlookeng.

the class TestCachedSqlQueryExecution method testQueriesWithCurrentPathFunction.

@Test
public void testQueriesWithCurrentPathFunction() throws Exception {
    setupWithExecutionPlanCacheEnabled(DEFAULT_SESSION);
    TestingMetadata metadata = new TestingMetadata();
    queryRunner.installPlugin(new TestPlugin(metadata));
    queryRunner.createCatalog("test", "test");
    SqlQueryManager manager = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    String query1 = "SELECT CURRENT_PATH";
    Plan plan1 = getPlan(query1, manager);
    setupWithExecutionPlanCacheEnabled(TPCH_SESSION);
    TestingMetadata metadata2 = new TestingMetadata();
    queryRunner.installPlugin(new TestPlugin(metadata2));
    queryRunner.createCatalog("test", "test");
    SqlQueryManager manager2 = (SqlQueryManager) queryRunner.getCoordinator().getQueryManager();
    Plan plan2 = getPlan(query1, manager2);
    assertNotNull(plan1);
    assertNotNull(plan2);
    // Should not have the same plan
    assertNotSame(plan1.getStatsAndCosts(), plan2.getStatsAndCosts());
    MaterializedResult rows1 = queryRunner.execute(DEFAULT_SESSION, query1);
    MaterializedResult rows2 = queryRunner.execute(TPCH_SESSION, query1);
    assertEquals(rows1.getRowCount(), rows2.getRowCount());
    MaterializedRow row1 = Iterables.getOnlyElement(rows1);
    MaterializedRow row2 = Iterables.getOnlyElement(rows2);
    assertEquals(row1.getFieldCount(), row2.getFieldCount());
    assertNotSame(row1.getFields(), row2.getFields());
}
Also used : TestingMetadata(io.prestosql.testing.TestingMetadata) Plan(io.prestosql.sql.planner.Plan) MaterializedResult(io.prestosql.testing.MaterializedResult) SqlQueryManager(io.prestosql.execution.SqlQueryManager) MaterializedRow(io.prestosql.testing.MaterializedRow) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Aggregations

SqlQueryManager (io.prestosql.execution.SqlQueryManager)19 Plan (io.prestosql.sql.planner.Plan)19 AfterTest (org.testng.annotations.AfterTest)19 Test (org.testng.annotations.Test)19 TestingMetadata (io.prestosql.testing.TestingMetadata)10 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)6 MaterializedResult (io.prestosql.testing.MaterializedResult)4 MaterializedRow (io.prestosql.testing.MaterializedRow)4