Search in sources :

Example 1 with NestableInput

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) DocTableInfo(io.crate.metadata.doc.DocTableInfo) Reference(io.crate.metadata.Reference) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) ResourceUnknownException(io.crate.exceptions.ResourceUnknownException) UnhandledServerException(io.crate.exceptions.UnhandledServerException) PartitionName(io.crate.metadata.PartitionName) ColumnIdent(io.crate.metadata.ColumnIdent) MapBackedRefResolver(io.crate.metadata.MapBackedRefResolver) UnhandledServerException(io.crate.exceptions.UnhandledServerException) RelationName(io.crate.metadata.RelationName)

Example 2 with NestableInput

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with NestableInput

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 4 with NestableInput

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());
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 5 with NestableInput

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";
}
Also used : NestableInput(io.crate.expression.NestableInput) Reference(io.crate.metadata.Reference) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

NestableInput (io.crate.expression.NestableInput)23 Reference (io.crate.metadata.Reference)22 Test (org.junit.Test)21 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)20 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)14 ShardRowContext (io.crate.expression.reference.sys.shard.ShardRowContext)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 MapBackedRefResolver (io.crate.metadata.MapBackedRefResolver)2 RelationName (io.crate.metadata.RelationName)2 ShardReferenceResolver (io.crate.metadata.shard.ShardReferenceResolver)2 HashMap (java.util.HashMap)2 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)2 IndexShard (org.elasticsearch.index.shard.IndexShard)2 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)1 UnhandledServerException (io.crate.exceptions.UnhandledServerException)1 PartitionName (io.crate.metadata.PartitionName)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1 Map (java.util.Map)1 IndexShardClosedException (org.elasticsearch.index.shard.IndexShardClosedException)1