Search in sources :

Example 6 with CreateTable

use of io.crate.sql.tree.CreateTable in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTableClusteredByPartitionedBy.

@Test
public void testBuildCreateTableClusteredByPartitionedBy() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "id", DataTypes.LONG), newReference(ident, "partition_column", DataTypes.STRING, null, null, true), newReference(ident, "cluster_column", DataTypes.STRING));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.of(columns.get(1)), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), new ColumnIdent("cluster_column"), ImmutableMap.<String, Object>of(), ImmutableList.of(columns.get(1).ident().columnIdent()), ColumnPolicy.DYNAMIC);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" LONG,\n" + "   \"partition_column\" STRING,\n" + "   \"cluster_column\" STRING\n" + ")\n" + "CLUSTERED BY (\"cluster_column\") INTO 5 SHARDS\n" + "PARTITIONED BY (\"partition_column\")\n" + "WITH (\n" + "   column_policy = 'dynamic',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 CreateTable (io.crate.sql.tree.CreateTable)6 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 Test (org.junit.Test)6 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayType (io.crate.types.ArrayType)1 HashMap (java.util.HashMap)1