Search in sources :

Example 11 with CreateTable

use of com.facebook.presto.sql.tree.CreateTable in project urban-eureka by errir503.

the class TestCreateTableTask method testCreateTableNotExistsFalse.

@Test
public void testCreateTableNotExistsFalse() {
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", true, emptyList(), Optional.empty())), false, ImmutableList.of(), Optional.empty());
    try {
        getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
        fail("expected exception");
    } catch (RuntimeException e) {
        // Expected
        assertTrue(e instanceof PrestoException);
        PrestoException prestoException = (PrestoException) e;
        assertEquals(prestoException.getErrorCode(), ALREADY_EXISTS.toErrorCode());
    }
    assertEquals(metadata.getCreateTableCallCount(), 1);
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) CreateTable(com.facebook.presto.sql.tree.CreateTable) PrestoException(com.facebook.presto.spi.PrestoException) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 12 with CreateTable

use of com.facebook.presto.sql.tree.CreateTable in project urban-eureka by errir503.

the class CreateTableVerification method match.

@Override
protected boolean match(CreateTable controlObject, CreateTable testObject, QueryObjectBundle control, QueryObjectBundle test) {
    controlObject = new CreateTable(DUMMY_TABLE_NAME, controlObject.getElements(), controlObject.isNotExists(), controlObject.getProperties(), controlObject.getComment());
    testObject = new CreateTable(DUMMY_TABLE_NAME, testObject.getElements(), testObject.isNotExists(), testObject.getProperties(), testObject.getComment());
    return Objects.equals(controlObject, testObject);
}
Also used : CreateTable(com.facebook.presto.sql.tree.CreateTable)

Example 13 with CreateTable

use of com.facebook.presto.sql.tree.CreateTable in project urban-eureka by errir503.

the class TooManyOpenPartitionsFailureResolver method resolveQueryFailure.

@Override
public Optional<String> resolveQueryFailure(QueryStats controlQueryStats, QueryException queryException, Optional<QueryObjectBundle> test) {
    if (!test.isPresent()) {
        return Optional.empty();
    }
    return mapMatchingPrestoException(queryException, TEST_MAIN, ImmutableSet.of(HIVE_TOO_MANY_OPEN_PARTITIONS), e -> {
        try {
            ShowCreate showCreate = new ShowCreate(TABLE, test.get().getObjectName());
            String showCreateResult = getOnlyElement(prestoAction.execute(showCreate, DESCRIBE, resultSet -> Optional.of(resultSet.getString(1))).getResults());
            CreateTable createTable = (CreateTable) sqlParser.createStatement(showCreateResult, ParsingOptions.builder().setDecimalLiteralTreatment(AS_DOUBLE).build());
            List<Property> bucketCountProperty = createTable.getProperties().stream().filter(property -> property.getName().getValue().equals(BUCKET_COUNT_PROPERTY)).collect(toImmutableList());
            if (bucketCountProperty.size() != 1) {
                return Optional.empty();
            }
            long bucketCount = ((LongLiteral) getOnlyElement(bucketCountProperty).getValue()).getValue();
            int testClusterSize = this.testClusterSizeSupplier.get();
            if (testClusterSize * maxBucketPerWriter < bucketCount) {
                return Optional.of("Not enough workers on test cluster");
            }
            return Optional.empty();
        } catch (Throwable t) {
            log.warn(t, "Exception when resolving HIVE_TOO_MANY_OPEN_PARTITIONS");
            return Optional.empty();
        }
    });
}
Also used : Logger(com.facebook.airlift.log.Logger) TEST_MAIN(com.facebook.presto.verifier.framework.QueryStage.TEST_MAIN) Suppliers.memoizeWithExpiration(com.google.common.base.Suppliers.memoizeWithExpiration) Supplier(java.util.function.Supplier) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) QueryObjectBundle(com.facebook.presto.verifier.framework.QueryObjectBundle) DESCRIBE(com.facebook.presto.verifier.framework.QueryStage.DESCRIBE) Objects.requireNonNull(java.util.Objects.requireNonNull) QueryStats(com.facebook.presto.jdbc.QueryStats) CreateTable(com.facebook.presto.sql.tree.CreateTable) ForTest(com.facebook.presto.verifier.annotation.ForTest) Property(com.facebook.presto.sql.tree.Property) ImmutableSet(com.google.common.collect.ImmutableSet) FailureResolverUtil.mapMatchingPrestoException(com.facebook.presto.verifier.resolver.FailureResolverUtil.mapMatchingPrestoException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HIVE_TOO_MANY_OPEN_PARTITIONS(com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) SqlParser(com.facebook.presto.sql.parser.SqlParser) QueryException(com.facebook.presto.verifier.framework.QueryException) List(java.util.List) AS_DOUBLE(com.facebook.presto.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DOUBLE) BUCKET_COUNT_PROPERTY(com.facebook.presto.hive.HiveTableProperties.BUCKET_COUNT_PROPERTY) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) PrestoAction(com.facebook.presto.verifier.prestoaction.PrestoAction) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) Optional(java.util.Optional) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) TABLE(com.facebook.presto.sql.tree.ShowCreate.Type.TABLE) LongLiteral(com.facebook.presto.sql.tree.LongLiteral) ShowCreate(com.facebook.presto.sql.tree.ShowCreate) CreateTable(com.facebook.presto.sql.tree.CreateTable) Property(com.facebook.presto.sql.tree.Property)

Example 14 with CreateTable

use of com.facebook.presto.sql.tree.CreateTable in project presto by prestodb.

the class TestCreateTableTask method testCreateWithNotNullColumns.

@Test
public void testCreateWithNotNullColumns() {
    metadata.setConnectorCapabilities(NOT_NULL_COLUMN_CONSTRAINT);
    List<TableElement> inputColumns = ImmutableList.of(new ColumnDefinition(identifier("a"), "DATE", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "VARCHAR", false, emptyList(), Optional.empty()), new ColumnDefinition(identifier("c"), "VARBINARY", false, emptyList(), Optional.empty()));
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), inputColumns, true, ImmutableList.of(), Optional.empty());
    getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
    assertEquals(metadata.getCreateTableCallCount(), 1);
    List<ColumnMetadata> columns = metadata.getReceivedTableMetadata().get(0).getColumns();
    assertEquals(columns.size(), 3);
    assertEquals(columns.get(0).getName(), "a");
    assertEquals(columns.get(0).getType().getDisplayName().toUpperCase(ENGLISH), "DATE");
    assertTrue(columns.get(0).isNullable());
    assertEquals(columns.get(1).getName(), "b");
    assertEquals(columns.get(1).getType().getDisplayName().toUpperCase(ENGLISH), "VARCHAR");
    assertFalse(columns.get(1).isNullable());
    assertEquals(columns.get(2).getName(), "c");
    assertEquals(columns.get(2).getType().getDisplayName().toUpperCase(ENGLISH), "VARBINARY");
    assertFalse(columns.get(2).isNullable());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) CreateTable(com.facebook.presto.sql.tree.CreateTable) TableElement(com.facebook.presto.sql.tree.TableElement) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Example 15 with CreateTable

use of com.facebook.presto.sql.tree.CreateTable in project presto by prestodb.

the class TestCreateTableTask method testCreateWithUnsupportedConnectorThrowsWhenNotNull.

@Test(expectedExceptions = SemanticException.class, expectedExceptionsMessageRegExp = ".*does not support non-null column for column name 'b'")
public void testCreateWithUnsupportedConnectorThrowsWhenNotNull() {
    List<TableElement> inputColumns = ImmutableList.of(new ColumnDefinition(identifier("a"), "DATE", true, emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "VARCHAR", false, emptyList(), Optional.empty()), new ColumnDefinition(identifier("c"), "VARBINARY", false, emptyList(), Optional.empty()));
    CreateTable statement = new CreateTable(QualifiedName.of("test_table"), inputColumns, true, ImmutableList.of(), Optional.empty());
    getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()));
}
Also used : AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) CreateTable(com.facebook.presto.sql.tree.CreateTable) TableElement(com.facebook.presto.sql.tree.TableElement) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Test(org.testng.annotations.Test)

Aggregations

CreateTable (com.facebook.presto.sql.tree.CreateTable)18 ColumnDefinition (com.facebook.presto.sql.tree.ColumnDefinition)12 Test (org.testng.annotations.Test)10 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)8 LikeClause (com.facebook.presto.sql.tree.LikeClause)6 Property (com.facebook.presto.sql.tree.Property)6 TableElement (com.facebook.presto.sql.tree.TableElement)6 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 PrestoException (com.facebook.presto.spi.PrestoException)4 Identifier (com.facebook.presto.sql.tree.Identifier)4 ImmutableList (com.google.common.collect.ImmutableList)4 ShowCreate (com.facebook.presto.sql.tree.ShowCreate)3 QueryException (com.facebook.presto.verifier.framework.QueryException)3 QueryObjectBundle (com.facebook.presto.verifier.framework.QueryObjectBundle)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 List (java.util.List)3 Optional (java.util.Optional)3 Logger (com.facebook.airlift.log.Logger)2 Session (com.facebook.presto.Session)2 HIVE_TOO_MANY_OPEN_PARTITIONS (com.facebook.presto.hive.HiveErrorCode.HIVE_TOO_MANY_OPEN_PARTITIONS)2