use of io.crate.expression.NestableInput in project crate by crate.
the class ShardReferenceResolver method createPartitionColumnResolver.
private static ReferenceResolver<NestableInput<?>> createPartitionColumnResolver(Index index, Schemas schemas) {
PartitionName partitionName;
try {
partitionName = PartitionName.fromIndexOrTemplate(index.getName());
} catch (IllegalArgumentException e) {
throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to load PARTITIONED BY columns from partition %s", index.getName()), e);
}
RelationName relationName = partitionName.relationName();
MapBuilder<ColumnIdent, NestableInput> builder = MapBuilder.newMapBuilder();
try {
DocTableInfo info = schemas.getTableInfo(relationName);
assert info.isPartitioned() : "table must be partitioned";
int i = 0;
int numPartitionedColumns = info.partitionedByColumns().size();
List<String> partitionValue = partitionName.values();
assert partitionValue.size() == numPartitionedColumns : "invalid number of partitioned columns";
for (Reference partitionedInfo : info.partitionedByColumns()) {
builder.put(partitionedInfo.column(), constant(partitionedInfo.valueType().implicitCast(partitionValue.get(i))));
i++;
}
} catch (Exception e) {
if (e instanceof ResourceUnknownException) {
LOGGER.error("Orphaned partition '{}' with missing table '{}' found", index, relationName.fqn());
} else {
throw e;
}
}
return new MapBackedRefResolver(builder.immutableMap());
}
use of io.crate.expression.NestableInput in project crate by crate.
the class SysShardsExpressionsTest method testMinLuceneVersion.
@Test
public void testMinLuceneVersion() throws Exception {
Reference refInfo = refInfo("sys.shards.min_lucene_version", DataTypes.STRING, RowGranularity.SHARD);
NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertEquals(Version.LATEST.toString(), shardExpression.value());
doThrow(new AlreadyClosedException("Already closed")).when(indexShard).minimumCompatibleVersion();
shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertThat(shardExpression.value(), nullValue());
}
use of io.crate.expression.NestableInput in project crate by crate.
the class SysShardsExpressionsTest method testPrimary.
@Test
public void testPrimary() throws Exception {
Reference refInfo = refInfo("sys.shards.primary", DataTypes.BOOLEAN, RowGranularity.SHARD);
NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertEquals(true, shardExpression.value());
}
use of io.crate.expression.NestableInput in project crate by crate.
the class SysShardsExpressionsTest method testRelocatingNode.
@Test
public void testRelocatingNode() throws Exception {
Reference refInfo = refInfo("sys.shards.relocating_node", DataTypes.STRING, RowGranularity.CLUSTER);
NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertEquals("node_X", shardExpression.value());
}
use of io.crate.expression.NestableInput in project crate by crate.
the class SysShardsExpressionsTest method testTableNameOfCustomSchema.
@Test
public void testTableNameOfCustomSchema() throws Exception {
// expression should return the real table name
indexName = "my_schema.wikipedia_de";
prepare();
Reference refInfo = refInfo("sys.shards.table_name", DataTypes.STRING, RowGranularity.SHARD);
NestableInput<String> shardExpression = (NestableInput<String>) resolver.getImplementation(refInfo);
assertEquals("wikipedia_de", shardExpression.value());
// reset indexName
indexName = "wikipedia_de";
}
Aggregations