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