Search in sources :

Example 61 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestBlackHoleSmoke method notAllPropertiesSetForDataGeneration.

@Test
public void notAllPropertiesSetForDataGeneration() {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    try {
        assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 3, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session);
        fail("Expected exception to be thrown here!");
    } catch (RuntimeException ex) {
    // expected exception
    }
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 62 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestBlackHoleSmoke method dataGenerationUsage.

@Test
public void dataGenerationUsage() {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 3, %s = 2, %s = 1 ) as SELECT * FROM tpch.tiny.nation", ROWS_PER_PAGE_PROPERTY, PAGES_PER_SPLIT_PROPERTY, SPLIT_COUNT_PROPERTY), 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    assertThatQueryReturnsValue("INSERT INTO nation SELECT * FROM tpch.tiny.nation", 25L, session);
    assertThatQueryReturnsValue("SELECT count(*) FROM nation", 6L, session);
    MaterializedResult rows = queryRunner.execute(session, "SELECT * FROM nation LIMIT 1");
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow row = Iterables.getOnlyElement(rows);
    assertEquals(row.getFieldCount(), 4);
    assertEquals(row.getField(0), 0L);
    assertEquals(row.getField(1), "****************");
    assertEquals(row.getField(2), 0L);
    assertEquals(row.getField(3), "****************");
    assertThatQueryReturnsValue("DROP TABLE nation", true);
}
Also used : MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 63 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestBlackHoleSmoke method pageProcessingDelay.

@Test
public void pageProcessingDelay() throws Exception {
    Session session = testSessionBuilder().setCatalog("blackhole").setSchema("default").build();
    Duration pageProcessingDelay = new Duration(1, SECONDS);
    assertThatQueryReturnsValue(format("CREATE TABLE nation WITH ( %s = 8, %s = 1, %s = 1, %s = 1, %s = '%s' ) AS " + "SELECT * FROM tpch.tiny.nation", FIELD_LENGTH_PROPERTY, ROWS_PER_PAGE_PROPERTY, PAGES_PER_SPLIT_PROPERTY, SPLIT_COUNT_PROPERTY, PAGE_PROCESSING_DELAY, pageProcessingDelay), 25L, session);
    Stopwatch stopwatch = Stopwatch.createStarted();
    assertEquals(queryRunner.execute(session, "SELECT * FROM nation").getRowCount(), 1);
    queryRunner.execute(session, "INSERT INTO nation SELECT CAST(null AS BIGINT), CAST(null AS VARCHAR(25)), CAST(null AS BIGINT), CAST(null AS VARCHAR(152))");
    stopwatch.stop();
    assertGreaterThan(stopwatch.elapsed(MILLISECONDS), pageProcessingDelay.toMillis());
    assertThatQueryReturnsValue("DROP TABLE nation", true);
}
Also used : Stopwatch(com.google.common.base.Stopwatch) Duration(io.airlift.units.Duration) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 64 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestDateTimeFunctions method testLocale.

@Test
public void testLocale() {
    Locale locale = Locale.JAPANESE;
    Session localeSession = testSessionBuilder().setTimeZoneKey(TIME_ZONE_KEY).setLocale(locale).build();
    FunctionAssertions localeAssertions = new FunctionAssertions(localeSession);
    String dateTimeLiteral = "TIMESTAMP '2001-01-09 13:04:05.321'";
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%a')", VARCHAR, "火");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%W')", VARCHAR, "火曜日");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%p')", VARCHAR, "午後");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%r')", VARCHAR, "01:04:05 午後");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%b')", VARCHAR, "1");
    localeAssertions.assertFunction("date_format(" + dateTimeLiteral + ", '%M')", VARCHAR, "1月");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'EEE')", VARCHAR, "火");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'EEEE')", VARCHAR, "火曜日");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'a')", VARCHAR, "午後");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'MMM')", VARCHAR, "1");
    localeAssertions.assertFunction("format_datetime(" + dateTimeLiteral + ", 'MMMM')", VARCHAR, "1月");
    localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 午後', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, toTimestamp(new DateTime(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE), localeSession));
    localeAssertions.assertFunction("date_parse('2013-05-17 12:35:10 午前', '%Y-%m-%d %h:%i:%s %p')", TimestampType.TIMESTAMP, toTimestamp(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE), localeSession));
    localeAssertions.assertFunction("parse_datetime('2013-05-17 12:35:10 午後', 'yyyy-MM-dd hh:mm:ss a')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(2013, 5, 17, 12, 35, 10, 0, DATE_TIME_ZONE)));
    localeAssertions.assertFunction("parse_datetime('2013-05-17 12:35:10 午前', 'yyyy-MM-dd hh:mm:ss aaa')", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(new DateTime(2013, 5, 17, 0, 35, 10, 0, DATE_TIME_ZONE)));
}
Also used : Locale(java.util.Locale) DateTime(org.joda.time.DateTime) Session(com.facebook.presto.Session) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) Test(org.testng.annotations.Test)

Example 65 with Session

use of com.facebook.presto.Session in project presto by prestodb.

the class TestMySqlIntegrationSmokeTest method testNameEscaping.

@Test
public void testNameEscaping() throws Exception {
    Session session = testSessionBuilder().setCatalog("mysql").setSchema("test_database").build();
    assertFalse(getQueryRunner().tableExists(session, "test_table"));
    assertUpdate(session, "CREATE TABLE test_table AS SELECT 123 x", 1);
    assertTrue(getQueryRunner().tableExists(session, "test_table"));
    assertQuery(session, "SELECT * FROM test_table", "SELECT 123");
    assertUpdate(session, "DROP TABLE test_table");
    assertFalse(getQueryRunner().tableExists(session, "test_table"));
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Aggregations

Session (com.facebook.presto.Session)121 Test (org.testng.annotations.Test)61 QueryId (com.facebook.presto.spi.QueryId)21 MaterializedResult (com.facebook.presto.testing.MaterializedResult)20 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)19 PrestoException (com.facebook.presto.spi.PrestoException)17 TransactionManager (com.facebook.presto.transaction.TransactionManager)16 AccessControl (com.facebook.presto.security.AccessControl)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)14 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)14 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)13 AccessControlManager (com.facebook.presto.security.AccessControlManager)13 ConnectorId (com.facebook.presto.connector.ConnectorId)12 LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)12 Type (com.facebook.presto.spi.type.Type)11 List (java.util.List)11 TableHandle (com.facebook.presto.metadata.TableHandle)10 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)10 Optional (java.util.Optional)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9