Search in sources :

Example 36 with PartitionName

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

the class InsertFromValuesAnalyzedStatement method generatePartitions.

public List<String> generatePartitions() {
    List<String> partitionValues = new ArrayList<>(partitionMaps.size());
    for (Map<String, String> map : partitionMaps) {
        List<BytesRef> values = new ArrayList<>(map.size());
        List<String> columnNames = partitionedByColumnNames();
        for (String columnName : columnNames) {
            values.add(BytesRefs.toBytesRef(map.get(columnName)));
        }
        PartitionName partitionName = new PartitionName(tableInfo().ident(), values);
        partitionValues.add(partitionName.asIndexName());
    }
    return partitionValues;
}
Also used : PartitionName(io.crate.metadata.PartitionName) ArrayList(java.util.ArrayList) BytesRef(org.apache.lucene.util.BytesRef)

Example 37 with PartitionName

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

the class DocTableInfoBuilder method buildPartitions.

private List<PartitionName> buildPartitions(DocIndexMetaData md) {
    List<PartitionName> partitions = new ArrayList<>();
    if (md.partitionedBy().size() > 0) {
        for (String index : concreteIndices) {
            if (PartitionName.isPartition(index)) {
                try {
                    PartitionName partitionName = PartitionName.fromIndexOrTemplate(index);
                    assert partitionName.tableIdent().equals(ident) : "ident must equal partitionName";
                    partitions.add(partitionName);
                } catch (IllegalArgumentException e) {
                    // ignore
                    logger.warn(String.format(Locale.ENGLISH, "Cannot build partition %s of index %s", index, ident.indexName()));
                }
            }
        }
    }
    return partitions;
}
Also used : PartitionName(io.crate.metadata.PartitionName) ArrayList(java.util.ArrayList)

Example 38 with PartitionName

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

the class WhereClauseAnalyzerTest method testWherePartitionedByColumn.

@Test
public void testWherePartitionedByColumn() throws Exception {
    DeleteAnalyzedStatement statement = e.analyze("delete from parted where date = 1395874800000");
    WhereClause whereClause = statement.whereClauses().get(0);
    assertThat(whereClause.hasQuery(), is(false));
    assertThat(whereClause.noMatch(), is(false));
    assertThat(whereClause.partitions(), Matchers.contains(new PartitionName("parted", Arrays.asList(new BytesRef("1395874800000"))).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) DeleteAnalyzedStatement(io.crate.analyze.DeleteAnalyzedStatement) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 39 with PartitionName

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

the class WhereClauseAnalyzerTest method init.

@Before
public void init() throws Exception {
    SQLExecutor.Builder builder = SQLExecutor.builder(new NoopClusterService());
    registerTables(builder);
    TestingTableInfo.Builder genInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, GENERATED_COL_TABLE_NAME), new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("ts", DataTypes.TIMESTAMP, null).add("x", DataTypes.INTEGER, null).add("y", DataTypes.LONG, null).addGeneratedColumn("day", DataTypes.TIMESTAMP, "date_trunc('day', ts)", true).addGeneratedColumn("minus_y", DataTypes.LONG, "y * -1", true).addGeneratedColumn("x_incr", DataTypes.LONG, "x + 1", false).addPartitions(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420070400000"), new BytesRef("-1"))).asIndexName(), new PartitionName("generated_col", Arrays.asList(new BytesRef("1420156800000"), new BytesRef("-2"))).asIndexName());
    builder.addDocTable(genInfo);
    TableIdent ident = new TableIdent(DocSchemaInfo.NAME, DOUBLE_GEN_PARTITIONED_TABLE_NAME);
    TestingTableInfo.Builder doubleGenPartedInfo = TestingTableInfo.builder(ident, new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of())).add("x", DataTypes.INTEGER, null).addGeneratedColumn("x1", DataTypes.LONG, "x+1", true).addGeneratedColumn("x2", DataTypes.LONG, "x+2", true).addPartitions(new PartitionName(ident, Arrays.asList(new BytesRef("4"), new BytesRef("5"))).toString(), new PartitionName(ident, Arrays.asList(new BytesRef("5"), new BytesRef("6"))).toString());
    builder.addDocTable(doubleGenPartedInfo);
    e = builder.build();
}
Also used : Routing(io.crate.metadata.Routing) TableIdent(io.crate.metadata.TableIdent) TestingTableInfo(io.crate.metadata.table.TestingTableInfo) PartitionName(io.crate.metadata.PartitionName) SQLExecutor(io.crate.testing.SQLExecutor) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BytesRef(org.apache.lucene.util.BytesRef) Before(org.junit.Before)

Example 40 with PartitionName

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

the class WhereClauseAnalyzerTest method testGtGenColOptimization.

@Test
public void testGtGenColOptimization() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from generated_col where ts > '2015-01-02T12:00:00'");
    assertThat(whereClause.partitions().size(), is(1));
    assertThat(whereClause.partitions().get(0), is(new PartitionName("generated_col", Arrays.asList(new BytesRef("1420156800000"), new BytesRef("-2"))).asIndexName()));
}
Also used : PartitionName(io.crate.metadata.PartitionName) WhereClause(io.crate.analyze.WhereClause) 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