use of io.crate.metadata.PartitionName in project crate by crate.
the class WhereClauseAnalyzerTest method testGenColRoundingFunctionNoSwappingOperatorOptimization.
@Test
public void testGenColRoundingFunctionNoSwappingOperatorOptimization() 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()));
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class DocTableInfoBuilderTest method testNoTableInfoFromOrphanedPartition.
@Test
public void testNoTableInfoFromOrphanedPartition() throws Exception {
String schemaName = randomSchema();
PartitionName partitionName = new PartitionName(schemaName, "test", Collections.singletonList(new BytesRef("boo")));
IndexMetaData.Builder indexMetaDataBuilder = IndexMetaData.builder(partitionName.asIndexName()).settings(Settings.builder().put("index.version.created", Version.CURRENT).build()).numberOfReplicas(0).numberOfShards(5).putMapping(Constants.DEFAULT_MAPPING_TYPE, "{" + " \"default\": {" + " \"properties\":{" + " \"id\": {" + " \"type\": \"integer\"," + " \"index\": \"not_analyzed\"" + " }" + " }" + " }" + "}");
MetaData metaData = MetaData.builder().put(indexMetaDataBuilder).build();
NoopClusterService clusterService = new NoopClusterService(ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build());
DocTableInfoBuilder builder = new DocTableInfoBuilder(functions, new TableIdent(schemaName, "test"), clusterService, new IndexNameExpressionResolver(Settings.EMPTY), mock(TransportPutIndexTemplateAction.class), executorService, false);
expectedException.expect(TableUnknownException.class);
expectedException.expectMessage(String.format(Locale.ENGLISH, "Table '%s.test' unknown", schemaName));
builder.build();
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class DocSchemaInfo method tableNames.
private Collection<String> tableNames() {
Set<String> tables = new HashSet<>();
Stream.of(clusterService.state().metaData().concreteAllOpenIndices()).filter(NO_BLOB).filter(NO_PARTITION).filter(this::indexMatchesSchema).map(DocSchemaInfo::getTableNameFromIndexName).forEach(tables::add);
// Search for partitioned table templates
UnmodifiableIterator<String> templates = clusterService.state().metaData().getTemplates().keysIt();
while (templates.hasNext()) {
String templateName = templates.next();
if (!PartitionName.isPartition(templateName)) {
continue;
}
try {
PartitionName partitionName = PartitionName.fromIndexOrTemplate(templateName);
TableIdent ti = partitionName.tableIdent();
if (schemaName.equalsIgnoreCase(ti.schema())) {
tables.add(ti.name());
}
} catch (IllegalArgumentException e) {
// do nothing
}
}
return tables;
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class FetchProjectorContext method partitionValues.
private Object[] partitionValues(String index, List<Reference> partitionByColumns) {
if (partitionByColumns.isEmpty()) {
return null;
}
PartitionName pn = PartitionName.fromIndexOrTemplate(index);
List<BytesRef> partitionRowValues = pn.values();
Object[] partitionValues = new Object[partitionRowValues.size()];
for (int i = 0; i < partitionRowValues.size(); i++) {
partitionValues[i] = partitionByColumns.get(i).valueType().value(partitionRowValues.get(i));
}
return partitionValues;
}
use of io.crate.metadata.PartitionName in project crate by crate.
the class TransportExecutorDDLTest method testCreateTableWithOrphanedAlias.
@Test
public void testCreateTableWithOrphanedAlias() throws Exception {
String partitionName = new PartitionName("test", Collections.singletonList(new BytesRef("foo"))).asIndexName();
client().admin().indices().prepareCreate(partitionName).addMapping(Constants.DEFAULT_MAPPING_TYPE, TEST_PARTITIONED_MAPPING).setSettings(TEST_SETTINGS).addAlias(new Alias("test")).execute().actionGet();
ensureGreen();
execute("create table test (id integer, name string, names string) " + "clustered into 2 shards " + "partitioned by (id) with (number_of_replicas=0)");
assertThat(response.rowCount(), is(1L));
ensureGreen();
execute("select * from information_schema.tables where table_name = 'test'");
assertThat(response.rowCount(), is(1L));
execute("select count(*) from information_schema.columns where table_name = 'test'");
assertThat((Long) response.rows()[0][0], is(3L));
// check that orphaned alias has been deleted
assertThat(client().admin().cluster().prepareState().execute().actionGet().getState().metaData().hasAlias("test"), is(false));
// check that orphaned partition has been deleted
assertThat(client().admin().indices().exists(new IndicesExistsRequest(partitionName)).actionGet().isExists(), is(false));
}
Aggregations