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);
}
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);
}
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();
}
});
}
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());
}
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()));
}
Aggregations