Search in sources :

Example 6 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class AlterTableAnalyzer method analyze.

public AlterTableAnalyzedStatement analyze(AlterTable node, Row parameters, String defaultSchema) {
    Table table = node.table();
    DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.of(table, defaultSchema));
    PartitionName partitionName = getPartitionName(table.partitionProperties(), tableInfo, parameters);
    TableParameterInfo tableParameterInfo = getTableParameterInfo(table, tableInfo, partitionName);
    TableParameter tableParameter = getTableParameter(node, parameters, tableParameterInfo);
    maybeRaiseBlockedException(tableInfo, tableParameter.settings());
    return new AlterTableAnalyzedStatement(tableInfo, partitionName, tableParameter, table.excludePartitions());
}
Also used : PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) AlterTable(io.crate.sql.tree.AlterTable) Table(io.crate.sql.tree.Table)

Example 7 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class PartitionPropertiesAnalyzerTest method testPartitionNameFromAssignmentWithBytesRef.

@Test
public void testPartitionNameFromAssignmentWithBytesRef() throws Exception {
    DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent("doc", "users"), new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("name", DataTypes.STRING, null, true).addPrimaryKey("name").build();
    PartitionName partitionName = PartitionPropertiesAnalyzer.toPartitionName(tableInfo, Arrays.asList(new Assignment(new QualifiedNameReference(new QualifiedName("name")), new StringLiteral("foo"))), Row.EMPTY);
    assertThat(partitionName.asIndexName(), is(".partitioned.users.0426crrf"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Assignment(io.crate.sql.tree.Assignment) DocTableInfo(io.crate.metadata.doc.DocTableInfo) StringLiteral(io.crate.sql.tree.StringLiteral) QualifiedName(io.crate.sql.tree.QualifiedName) Routing(io.crate.metadata.Routing) TableIdent(io.crate.metadata.TableIdent) List(java.util.List) QualifiedNameReference(io.crate.sql.tree.QualifiedNameReference) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class RefreshAnalyzerTest method testRefreshPartition.

@Test
public void testRefreshPartition() throws Exception {
    PartitionName partition = new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000")));
    RefreshTableAnalyzedStatement analysis = e.analyze("refresh table parted PARTITION (date=1395874800000)");
    assertThat(analysis.indexNames(), contains(".partitioned.parted.04732cpp6ks3ed1o60o30c1g"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testRestoreSinglePartition.

@Test
public void testRestoreSinglePartition() throws Exception {
    RestoreSnapshotAnalyzedStatement statement = analyze("RESTORE SNAPSHOT my_repo.my_snapshot TABLE parted PARTITION (date=123)");
    PartitionName partition = new PartitionName("parted", ImmutableList.of(new BytesRef("123")));
    assertThat(statement.restoreTables().size(), is(1));
    assertThat(statement.restoreTables().get(0).partitionName(), is(partition));
    assertThat(statement.restoreTables().get(0).tableIdent(), is(new TableIdent(null, "parted")));
}
Also used : PartitionName(io.crate.metadata.PartitionName) TableIdent(io.crate.metadata.TableIdent) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with PartitionName

use of io.crate.metadata.PartitionName in project crate by crate.

the class SnapshotRestoreAnalyzerTest method testRestoreSinglePartitionToUnknownTable.

@Test
public void testRestoreSinglePartitionToUnknownTable() throws Exception {
    RestoreSnapshotAnalyzedStatement statement = analyze("RESTORE SNAPSHOT my_repo.my_snapshot TABLE unknown_parted PARTITION (date=123)");
    PartitionName partitionName = new PartitionName("unknown_parted", ImmutableList.of(new BytesRef("123")));
    assertThat(statement.restoreTables().size(), is(1));
    assertThat(statement.restoreTables().get(0).partitionName(), is(partitionName));
    assertThat(statement.restoreTables().get(0).tableIdent(), is(new TableIdent(null, "unknown_parted")));
}
Also used : PartitionName(io.crate.metadata.PartitionName) TableIdent(io.crate.metadata.TableIdent) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

PartitionName (io.crate.metadata.PartitionName)58 BytesRef (org.apache.lucene.util.BytesRef)50 Test (org.junit.Test)44 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)10 WhereClause (io.crate.analyze.WhereClause)8 TableIdent (io.crate.metadata.TableIdent)8 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)7 Settings (org.elasticsearch.common.settings.Settings)7 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)5 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)5 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)4 SQLResponse (io.crate.testing.SQLResponse)4 Map (java.util.Map)4 Table (io.crate.sql.tree.Table)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3 MetaData (org.elasticsearch.cluster.metadata.MetaData)3