@Test public void testAddColumn() { assertStatement("ALTER TABLE foo.t ADD COLUMN c bigint", new AddColumn(QualifiedName.of("foo", "t"), new ColumnDefinition(identifier("c"), "bigint", emptyList(), Optional.empty()))); }
@Test public void testCreateTableNotExistsTrue() { CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", emptyList(), Optional.empty())), true, ImmutableList.of(), Optional.empty()); getFutureValue(new CreateTableTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList())); assertEquals(metadata.getCreateTableCallCount(), 1); }
@Override public Node visitColumnDefinition(SqlBaseParser.ColumnDefinitionContext context) { Optional<String> comment = Optional.empty(); if (context.COMMENT() != null) { comment = Optional.of(((StringLiteral) visit(context.string())).getValue()); } List<Property> properties = ImmutableList.of(); if (context.properties() != null) { properties = visit(context.properties().property(), Property.class); } return new ColumnDefinition( getLocation(context), (Identifier) visit(context.identifier()), getType(context.type()), properties, comment); }
@Test public void testCreateTableNotExistsFalse() { CreateTable statement = new CreateTable(QualifiedName.of("test_table"), ImmutableList.of(new ColumnDefinition(identifier("a"), "BIGINT", 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); }
.map(column -> { List<Property> propertyNodes = buildProperties(objectName, Optional.of(column.getName()), INVALID_COLUMN_PROPERTY, column.getProperties(), allColumnProperties); return new ColumnDefinition(new Identifier(column.getName()), column.getType().getDisplayName(), propertyNodes, Optional.ofNullable(column.getComment())); }) .collect(toImmutableList());
new CreateTable(QualifiedName.of("foo"), ImmutableList.of( new ColumnDefinition(identifier("a"), "VARCHAR", emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "BIGINT", emptyList(), Optional.of("hello world")), new ColumnDefinition(identifier("c"), "IPADDRESS", emptyList(), Optional.empty())), false, ImmutableList.of(), assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty())), true, ImmutableList.of(), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", ImmutableList.of( new Property(new Identifier("nullable"), BooleanLiteral.TRUE_LITERAL), new Property(new Identifier("compression"), new StringLiteral("LZ4")) new CreateTable(QualifiedName.of("bar"), ImmutableList.of( new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty())), new CreateTable(QualifiedName.of("bar"), ImmutableList.of( new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty()),
TableModel tm = new CustomTableModel( new ColumnDefinition("Lfd. Nr.", Integer.class), new ColumnDefinition("FB Nr.", String.class), ...)
@Test public void testAddColumn() { assertStatement("ALTER TABLE foo.t ADD COLUMN c bigint", new AddColumn(QualifiedName.of("foo", "t"), new ColumnDefinition(identifier("c"), "bigint", emptyList(), Optional.empty()))); }
@Override public Node visitColumnDefinition(SqlBaseParser.ColumnDefinitionContext context) { Optional<String> comment = Optional.empty(); if (context.COMMENT() != null) { comment = Optional.of(((StringLiteral) visit(context.string())).getValue()); } List<Property> properties = ImmutableList.of(); if (context.properties() != null) { properties = visit(context.properties().property(), Property.class); } return new ColumnDefinition( getLocation(context), (Identifier) visit(context.identifier()), getType(context.type()), properties, comment); }
new CreateTable(QualifiedName.of("foo"), ImmutableList.of( new ColumnDefinition(identifier("a"), "VARCHAR", emptyList(), Optional.empty()), new ColumnDefinition(identifier("b"), "BIGINT", emptyList(), Optional.of("hello world")), new ColumnDefinition(identifier("c"), "IPADDRESS", emptyList(), Optional.empty())), false, ImmutableList.of(), assertStatement("CREATE TABLE IF NOT EXISTS bar (c TIMESTAMP)", new CreateTable(QualifiedName.of("bar"), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty())), true, ImmutableList.of(), ImmutableList.of(new ColumnDefinition(identifier("c"), "TIMESTAMP", ImmutableList.of( new Property(new Identifier("nullable"), BooleanLiteral.TRUE_LITERAL), new Property(new Identifier("compression"), new StringLiteral("LZ4")) new CreateTable(QualifiedName.of("bar"), ImmutableList.of( new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty())), new CreateTable(QualifiedName.of("bar"), ImmutableList.of( new ColumnDefinition(identifier("c"), "TIMESTAMP", emptyList(), Optional.empty()), new LikeClause(QualifiedName.of("like_table"), Optional.empty()),