org.intellij.lang.annotations.Language Java Examples
The following examples show how to use
org.intellij.lang.annotations.Language.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryAssertions.java From presto with Apache License 2.0 | 6 votes |
public QueryAssert matches(@Language("SQL") String query) { MaterializedResult expected = runner.execute(session, query); return satisfies(actual -> { assertThat(actual.getTypes()) .as("Output types") .isEqualTo(expected.getTypes()); ListAssert<MaterializedRow> assertion = assertThat(actual.getMaterializedRows()) .as("Rows") .withRepresentation(ROWS_REPRESENTATION); if (ordered) { assertion.containsExactlyElementsOf(expected.getMaterializedRows()); } else { assertion.containsExactlyInAnyOrderElementsOf(expected.getMaterializedRows()); } }); }
Example #2
Source File: TestReorderWindows.java From presto with Apache License 2.0 | 6 votes |
@Test public void testNonMergeableABAReordersToAAB() { @Language("SQL") String sql = "select " + "sum(quantity) over(PARTITION BY suppkey ORDER BY orderkey ASC NULLS LAST) sum_quantity_A, " + "avg(discount) over(PARTITION BY partkey ORDER BY receiptdate ASC NULLS LAST) avg_discount_B, " + "min(tax) over(PARTITION BY suppkey ORDER BY shipdate ASC NULLS LAST) min_tax_A " + "from lineitem"; assertUnitPlan(sql, anyTree( window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowAp) .addFunction(functionCall("min", commonFrame, ImmutableList.of(TAX_ALIAS))), window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowA) .addFunction(functionCall("sum", commonFrame, ImmutableList.of(QUANTITY_ALIAS))), window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowB) .addFunction(functionCall("avg", commonFrame, ImmutableList.of(DISCOUNT_ALIAS))), LINEITEM_TABLESCAN_DOQPRSST))))); // should be anyTree(LINEITEM_TABLESCANE_DOQPRSST) but anyTree does not handle zero nodes case correctly }
Example #3
Source File: TestReorderWindows.java From presto with Apache License 2.0 | 6 votes |
@Test public void testNonMergeableABAReordersToAABAllOptimizers() { @Language("SQL") String sql = "select " + "sum(quantity) over(PARTITION BY suppkey ORDER BY orderkey ASC NULLS LAST) sum_quantity_A, " + "avg(discount) over(PARTITION BY partkey ORDER BY receiptdate ASC NULLS LAST) avg_discount_B, " + "min(tax) over(PARTITION BY suppkey ORDER BY shipdate ASC NULLS LAST) min_tax_A " + "from lineitem"; PlanMatchPattern pattern = anyTree( window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowAp) .addFunction(functionCall("min", commonFrame, ImmutableList.of(TAX_ALIAS))), project( window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowA) .addFunction(functionCall("sum", commonFrame, ImmutableList.of(QUANTITY_ALIAS))), project( window(windowMatcherBuilder -> windowMatcherBuilder .specification(windowB) .addFunction(functionCall("avg", commonFrame, ImmutableList.of(DISCOUNT_ALIAS))), anyTree(LINEITEM_TABLESCAN_DOQPRSST))))))); assertPlan(sql, pattern); }
Example #4
Source File: TestShardCleaner.java From presto with Apache License 2.0 | 6 votes |
private List<List<Object>> select(@Language("SQL") String sql) { return dbi.withHandle(handle -> handle.createQuery(sql) .map((index, rs, context) -> { int count = rs.getMetaData().getColumnCount(); List<Object> row = new ArrayList<>(count); for (int i = 1; i <= count; i++) { Object value = rs.getObject(i); if (value instanceof byte[]) { value = uuidFromBytes((byte[]) value); } row.add(value); } return row; }) .list()); }
Example #5
Source File: TestIcebergSmoke.java From presto with Apache License 2.0 | 6 votes |
private void testCreatePartitionedTableWithNestedTypes(Session session, FileFormat fileFormat) { @Language("SQL") String createTable = "" + "CREATE TABLE test_partitioned_table_nested_type (" + " _string VARCHAR" + ", _struct ROW(_field1 INT, _field2 VARCHAR)" + ", _date DATE" + ") " + "WITH (" + "format = '" + fileFormat + "', " + "partitioning = ARRAY['_date']" + ")"; assertUpdate(session, createTable); dropTable(session, "test_partitioned_table_nested_type"); }
Example #6
Source File: TestMemorySmoke.java From presto with Apache License 2.0 | 6 votes |
@Test public void testViews() { @Language("SQL") String query = "SELECT orderkey, orderstatus, totalprice / 2 half FROM orders"; assertUpdate("CREATE VIEW test_view AS SELECT 123 x"); assertUpdate("CREATE OR REPLACE VIEW test_view AS " + query); assertQueryFails("CREATE TABLE test_view (x date)", "View \\[default.test_view] already exists"); assertQueryFails("CREATE VIEW test_view AS SELECT 123 x", "View already exists: default.test_view"); assertQuery("SELECT * FROM test_view", query); assertTrue(computeActual("SHOW TABLES").getOnlyColumnAsSet().contains("test_view")); assertUpdate("DROP VIEW test_view"); assertQueryFails("DROP VIEW test_view", "line 1:1: View 'memory.default.test_view' does not exist"); }
Example #7
Source File: TestExpressionInterpreter.java From presto with Apache License 2.0 | 6 votes |
private static Expression planExpression(@Language("SQL") String expression) { return TransactionBuilder.transaction(new TestingTransactionManager(), new AllowAllAccessControl()) .singleStatement() .execute(TEST_SESSION, transactionSession -> { Expression parsedExpression = SQL_PARSER.createExpression(expression, createParsingOptions(transactionSession)); parsedExpression = rewriteIdentifiersToSymbolReferences(parsedExpression); parsedExpression = resolveFunctionCalls(METADATA, transactionSession, SYMBOL_TYPES, parsedExpression); parsedExpression = CanonicalizeExpressionRewriter.rewrite( parsedExpression, transactionSession, METADATA, new TypeAnalyzer(SQL_PARSER, METADATA), SYMBOL_TYPES); return parsedExpression; }); }
Example #8
Source File: AbstractTestEngineOnlyQueries.java From presto with Apache License 2.0 | 6 votes |
@Test public void testLocallyUnrepresentableTimeLiterals() { LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp) @Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss.SSS''").format(localTimeThatDidNotExist); assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date) sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight); assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone"); checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone"); sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101); assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner }
Example #9
Source File: EventsAwaitingQueries.java From presto with Apache License 2.0 | 6 votes |
MaterializedResult runQueryAndWaitForEvents(@Language("SQL") String sql, int numEventsExpected, Session alternateSession, Optional<String> expectedExceptionRegEx) throws Exception { eventsBuilder.initialize(numEventsExpected); MaterializedResult result = null; try { result = queryRunner.execute(alternateSession, sql); } catch (RuntimeException exception) { if (expectedExceptionRegEx.isPresent()) { String regex = expectedExceptionRegEx.get(); if (!nullToEmpty(exception.getMessage()).matches(regex)) { fail(format("Expected exception message '%s' to match '%s' for query: %s", exception.getMessage(), regex, sql), exception); } } else { throw exception; } } eventsBuilder.waitForEvents(10); return result; }
Example #10
Source File: TestDeprecatedFunctionWarning.java From presto with Apache License 2.0 | 6 votes |
private static void assertPlannerWarnings(QueryRunner queryRunner, @Language("SQL") String sql, List<WarningCode> expectedWarnings) { Session session = testSessionBuilder() .setCatalog("tpch") .setSchema("tiny") .build(); Set<Integer> warnings = queryRunner.execute(session, sql).getWarnings().stream() .map(Warning::getWarningCode) .map(Warning.Code::getCode) .collect(toImmutableSet()); expectedWarnings.stream() .map(WarningCode::getCode) .forEach(expectedWarning -> { if (!warnings.contains(expectedWarning)) { fail("Expected warning: " + expectedWarning); } }); if (expectedWarnings.isEmpty() && !warnings.isEmpty()) { fail("Expect no warning"); } }
Example #11
Source File: TestExpressionEquivalence.java From presto with Apache License 2.0 | 6 votes |
private static void assertNotEquivalent(@Language("SQL") String left, @Language("SQL") String right) { ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE /* anything */); Expression leftExpression = planExpression(METADATA, TEST_SESSION, TYPE_PROVIDER, SQL_PARSER.createExpression(left, parsingOptions)); Expression rightExpression = planExpression(METADATA, TEST_SESSION, TYPE_PROVIDER, SQL_PARSER.createExpression(right, parsingOptions)); Set<Symbol> symbols = extractUnique(ImmutableList.of(leftExpression, rightExpression)); TypeProvider types = TypeProvider.copyOf(symbols.stream() .collect(toMap(identity(), TestExpressionEquivalence::generateType))); assertFalse( areExpressionEquivalent(leftExpression, rightExpression, types), format("Expected (%s) and (%s) to not be equivalent", left, right)); assertFalse( areExpressionEquivalent(rightExpression, leftExpression, types), format("Expected (%s) and (%s) to not be equivalent", right, left)); }
Example #12
Source File: AbstractTestQueryFramework.java From presto with Apache License 2.0 | 6 votes |
protected void assertAccessDenied( Session session, @Language("SQL") String sql, @Language("RegExp") String exceptionsMessageRegExp, TestingPrivilege... deniedPrivileges) { executeExclusively(() -> { try { queryRunner.getAccessControl().deny(deniedPrivileges); queryRunner.execute(session, sql); fail("Expected " + AccessDeniedException.class.getSimpleName()); } catch (RuntimeException e) { assertExceptionMessage(sql, e, ".*Access Denied: " + exceptionsMessageRegExp); } finally { queryRunner.getAccessControl().reset(); } }); }
Example #13
Source File: StandaloneQueryRunner.java From presto with Apache License 2.0 | 5 votes |
@Override public MaterializedResult execute(Session session, @Language("SQL") String sql) { lock.readLock().lock(); try { return prestoClient.execute(session, sql).getResult(); } finally { lock.readLock().unlock(); } }
Example #14
Source File: TestEventListener.java From presto with Apache License 2.0 | 5 votes |
private void assertFailedQuery(@Language("SQL") String sql, String expectedFailure) throws Exception { queries.runQueryAndWaitForEvents(sql, 2, session, Optional.of(expectedFailure)); QueryCompletedEvent queryCompletedEvent = getOnlyElement(generatedEvents.getQueryCompletedEvents()); assertEquals(sql, queryCompletedEvent.getMetadata().getQuery()); QueryFailureInfo failureInfo = queryCompletedEvent.getFailureInfo() .orElseThrow(() -> new AssertionError("Expected query event to be failed")); assertEquals(expectedFailure, failureInfo.getFailureMessage().orElse(null)); }
Example #15
Source File: StandaloneQueryRunner.java From presto with Apache License 2.0 | 5 votes |
@Override public MaterializedResult execute(@Language("SQL") String sql) { lock.readLock().lock(); try { return prestoClient.execute(sql).getResult(); } finally { lock.readLock().unlock(); } }
Example #16
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public void assertQueryReturnsEmptyResult(@Language("SQL") String actual) { MaterializedResult actualResults = null; try { actualResults = execute(actual); } catch (RuntimeException ex) { fail("Execution of 'actual' query failed: " + actual, ex); } List<MaterializedRow> actualRows = actualResults.getMaterializedRows(); assertEquals(actualRows.size(), 0); }
Example #17
Source File: TestPlannerWarnings.java From presto with Apache License 2.0 | 5 votes |
public static void assertPlannerWarnings(LocalQueryRunner queryRunner, @Language("SQL") String sql, Map<String, String> sessionProperties, List<WarningCode> expectedWarnings, Optional<List<Rule<?>>> rules) { Session.SessionBuilder sessionBuilder = testSessionBuilder() .setCatalog(queryRunner.getDefaultSession().getCatalog().get()) .setSchema(queryRunner.getDefaultSession().getSchema().get()); sessionProperties.forEach(sessionBuilder::setSystemProperty); WarningCollector warningCollector = new DefaultWarningCollector(new WarningCollectorConfig()); try { queryRunner.inTransaction(sessionBuilder.build(), transactionSession -> { if (rules.isPresent()) { createPlan(queryRunner, transactionSession, sql, warningCollector, rules.get()); } else { queryRunner.createPlan(transactionSession, sql, CREATED, false, warningCollector); } return null; }); } catch (PrestoException e) { // ignore } Set<WarningCode> warnings = warningCollector.getWarnings().stream() .map(PrestoWarning::getWarningCode) .collect(toImmutableSet()); for (WarningCode expectedWarning : expectedWarnings) { if (!warnings.contains(expectedWarning)) { fail("Expected warning: " + expectedWarning); } } }
Example #18
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public static void assertQuery( QueryRunner actualQueryRunner, Session session, @Language("SQL") String actual, H2QueryRunner h2QueryRunner, @Language("SQL") String expected, boolean ensureOrdering, boolean compareUpdate) { assertQuery(actualQueryRunner, session, actual, h2QueryRunner, expected, ensureOrdering, compareUpdate, Optional.empty()); }
Example #19
Source File: TestAnalyzer.java From presto with Apache License 2.0 | 5 votes |
private void analyze(Session clientSession, @Language("SQL") String query) { transaction(transactionManager, accessControl) .singleStatement() .readUncommitted() .execute(clientSession, session -> { Analyzer analyzer = createAnalyzer(session, metadata); Statement statement = SQL_PARSER.createStatement(query, new ParsingOptions()); analyzer.analyze(statement); }); }
Example #20
Source File: TestMergeWindows.java From presto with Apache License 2.0 | 5 votes |
@Test public void testIdenticalWindowSpecificationsAAfilterA() { @Language("SQL") String sql = "" + "SELECT" + " sum_discount_A, " + " SUM(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_quantity_A, " + " AVG(quantity) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) avg_quantity_A " + "FROM (" + " SELECT" + " *, " + " SUM(discount) OVER (PARTITION BY suppkey ORDER BY orderkey ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) sum_discount_A " + " FROM lineitem)" + "WHERE shipdate IS NOT NULL"; assertUnitPlan(sql, anyTree( window(windowMatcherBuilder -> windowMatcherBuilder .specification(specificationA) .addFunction(functionCall("sum", COMMON_FRAME, ImmutableList.of(QUANTITY_ALIAS))) .addFunction(functionCall("avg", COMMON_FRAME, ImmutableList.of(QUANTITY_ALIAS))), filter(SHIPDATE_ALIAS + " IS NOT NULL", project( window(windowMatcherBuilder -> windowMatcherBuilder .specification(specificationA) .addFunction(functionCall("sum", COMMON_FRAME, ImmutableList.of(DISCOUNT_ALIAS))), LINEITEM_TABLESCAN_DOQSS)))))); }
Example #21
Source File: TestPostgreSqlIntegrationSmokeTest.java From presto with Apache License 2.0 | 5 votes |
@Test public void testInsertIntoNotNullColumn() { @Language("SQL") String createTableSql = format("" + "CREATE TABLE %s.tpch.test_insert_not_null (\n" + " column_a date,\n" + " column_b date NOT NULL\n" + ")", getSession().getCatalog().get()); assertUpdate(createTableSql); assertEquals(computeScalar("SHOW CREATE TABLE test_insert_not_null"), createTableSql); assertQueryFails("INSERT INTO test_insert_not_null (column_a) VALUES (date '2012-12-31')", "(?s).*null value in column \"column_b\" violates not-null constraint.*"); assertQueryFails("INSERT INTO test_insert_not_null (column_a, column_b) VALUES (date '2012-12-31', null)", "NULL value not allowed for NOT NULL column: column_b"); assertUpdate("ALTER TABLE test_insert_not_null ADD COLUMN column_c BIGINT NOT NULL"); createTableSql = format("" + "CREATE TABLE %s.tpch.test_insert_not_null (\n" + " column_a date,\n" + " column_b date NOT NULL,\n" + " column_c bigint NOT NULL\n" + ")", getSession().getCatalog().get()); assertEquals(computeScalar("SHOW CREATE TABLE test_insert_not_null"), createTableSql); assertQueryFails("INSERT INTO test_insert_not_null (column_b) VALUES (date '2012-12-31')", "(?s).*null value in column \"column_c\" violates not-null constraint.*"); assertQueryFails("INSERT INTO test_insert_not_null (column_b, column_c) VALUES (date '2012-12-31', null)", "NULL value not allowed for NOT NULL column: column_c"); assertUpdate("INSERT INTO test_insert_not_null (column_b, column_c) VALUES (date '2012-12-31', 1)", 1); assertUpdate("INSERT INTO test_insert_not_null (column_a, column_b, column_c) VALUES (date '2013-01-01', date '2013-01-02', 2)", 1); assertQuery( "SELECT * FROM test_insert_not_null", "VALUES (NULL, CAST('2012-12-31' AS DATE), 1), (CAST('2013-01-01' AS DATE), CAST('2013-01-02' AS DATE), 2)"); assertUpdate("DROP TABLE test_insert_not_null"); }
Example #22
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
/** * @deprecated use {@link org.assertj.core.api.Assertions#assertThatThrownBy(ThrowableAssert.ThrowingCallable)}: * <pre> * assertThatThrownBy(() -> assertions.execute(sql))<br> * .hasMessage(...) * </pre> */ public void assertFails(@Language("SQL") String sql, @Language("RegExp") String expectedMessageRegExp) { try { runner.execute(runner.getDefaultSession(), sql).toTestTypes(); fail(format("Expected query to fail: %s", sql)); } catch (RuntimeException exception) { exception.addSuppressed(new Exception("Query: " + sql)); assertThat(exception) .isInstanceOf(PrestoException.class) .hasMessageMatching(expectedMessageRegExp); } }
Example #23
Source File: TestAtopSmoke.java From presto with Apache License 2.0 | 5 votes |
private void assertThatQueryReturnsValue(@Language("SQL") String sql, Object expected) { MaterializedResult rows = queryRunner.execute(sql); MaterializedRow materializedRow = Iterables.getOnlyElement(rows); int fieldCount = materializedRow.getFieldCount(); assertTrue(fieldCount == 1, format("Expected only one column, but got '%d'", fieldCount)); Object value = materializedRow.getField(0); assertEquals(value, expected); assertTrue(Iterables.getOnlyElement(rows).getFieldCount() == 1); }
Example #24
Source File: TestMergeWindows.java From presto with Apache License 2.0 | 5 votes |
@Test public void testIdenticalWindowSpecificationsDefaultFrame() { ExpectedValueProvider<WindowNode.Specification> specificationC = specification( ImmutableList.of(SUPPKEY_ALIAS), ImmutableList.of(ORDERKEY_ALIAS), ImmutableMap.of(ORDERKEY_ALIAS, SortOrder.ASC_NULLS_LAST)); ExpectedValueProvider<WindowNode.Specification> specificationD = specification( ImmutableList.of(ORDERKEY_ALIAS), ImmutableList.of(SHIPDATE_ALIAS), ImmutableMap.of(SHIPDATE_ALIAS, SortOrder.ASC_NULLS_LAST)); @Language("SQL") String sql = "SELECT " + "SUM(quantity) OVER (PARTITION By suppkey ORDER BY orderkey), " + "SUM(quantity) OVER (PARTITION BY orderkey ORDER BY shipdate), " + "SUM(discount) OVER (PARTITION BY suppkey ORDER BY orderkey) " + "FROM lineitem"; assertUnitPlan(sql, anyTree( window(windowMatcherBuilder -> windowMatcherBuilder .specification(specificationC) .addFunction(functionCall("sum", UNSPECIFIED_FRAME, ImmutableList.of(QUANTITY_ALIAS))) .addFunction(functionCall("sum", UNSPECIFIED_FRAME, ImmutableList.of(DISCOUNT_ALIAS))), window(windowMatcherBuilder -> windowMatcherBuilder .specification(specificationD) .addFunction(functionCall("sum", UNSPECIFIED_FRAME, ImmutableList.of(QUANTITY_ALIAS))), LINEITEM_TABLESCAN_DOQSS)))); }
Example #25
Source File: DistributedQueryRunner.java From presto with Apache License 2.0 | 5 votes |
@Override public MaterializedResult execute(@Language("SQL") String sql) { lock.readLock().lock(); try { return prestoClient.execute(sql).getResult(); } finally { lock.readLock().unlock(); } }
Example #26
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public ExpressionAssert matches(@Language("SQL") String expression) { MaterializedResult result = runner.execute(session, "VALUES " + expression); Type expectedType = result.getTypes().get(0); Object expectedValue = result.getOnlyColumnAsSet().iterator().next(); return satisfies(actual -> { assertThat(actualType).as("Type") .isEqualTo(expectedType); assertThat(actual) .withRepresentation(TYPE_RENDERER) .isEqualTo(expectedValue); }); }
Example #27
Source File: HiveQueryRunner.java From presto with Apache License 2.0 | 5 votes |
private static void copyTableBucketed(QueryRunner queryRunner, QualifiedObjectName table, Session session) { long start = System.nanoTime(); log.info("Running import for %s", table.getObjectName()); @Language("SQL") String sql; switch (table.getObjectName()) { case "part": case "partsupp": case "supplier": case "nation": case "region": sql = format("CREATE TABLE %s AS SELECT * FROM %s", table.getObjectName(), table); break; case "lineitem": sql = format("CREATE TABLE %s WITH (bucketed_by=array['orderkey'], bucket_count=11) AS SELECT * FROM %s", table.getObjectName(), table); break; case "customer": sql = format("CREATE TABLE %s WITH (bucketed_by=array['custkey'], bucket_count=11) AS SELECT * FROM %s", table.getObjectName(), table); break; case "orders": sql = format("CREATE TABLE %s WITH (bucketed_by=array['custkey'], bucket_count=11) AS SELECT * FROM %s", table.getObjectName(), table); break; default: throw new UnsupportedOperationException(); } long rows = (Long) queryRunner.execute(session, sql).getMaterializedRows().get(0).getField(0); log.info("Imported %s rows for %s in %s", rows, table.getObjectName(), nanosSince(start).convertToMostSuccinctTimeUnit()); }
Example #28
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public static void copyTable(QueryRunner queryRunner, QualifiedObjectName table, Session session) { long start = System.nanoTime(); log.info("Running import for %s", table.getObjectName()); @Language("SQL") String sql = format("CREATE TABLE %s AS SELECT * FROM %s", table.getObjectName(), table); long rows = (Long) queryRunner.execute(session, sql).getMaterializedRows().get(0).getField(0); log.info("Imported %s rows for %s in %s", rows, table.getObjectName(), nanosSince(start).convertToMostSuccinctTimeUnit()); }
Example #29
Source File: TestHiveCreateExternalTableDisabled.java From presto with Apache License 2.0 | 5 votes |
@Test public void testCreateExternalTableWithData() throws Exception { File tempDir = createTempDir(); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", tempDir.toURI().toASCIIString()); assertQueryFails(createTableSql, "Creating non-managed Hive tables is disabled"); deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); }
Example #30
Source File: QueryAssertions.java From presto with Apache License 2.0 | 5 votes |
public void assertQueryAndPlan( @Language("SQL") String actual, @Language("SQL") String expected, PlanMatchPattern pattern) { assertQuery(actual, expected); Plan plan = runner.executeWithPlan(runner.getDefaultSession(), actual, WarningCollector.NOOP).getQueryPlan(); PlanAssert.assertPlan(runner.getDefaultSession(), runner.getMetadata(), runner.getStatsCalculator(), plan, pattern); }