Search in sources :

Example 36 with RelationName

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

the class TestingHelpers method refInfo.

public static Reference refInfo(String fqColumnName, DataType dataType, RowGranularity rowGranularity, String... nested) {
    String[] parts = fqColumnName.split("\\.");
    ReferenceIdent refIdent;
    List<String> nestedParts = null;
    if (nested.length > 0) {
        nestedParts = Arrays.asList(nested);
    }
    switch(parts.length) {
        case 2:
            refIdent = new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, parts[0]), parts[1], nestedParts);
            break;
        case 3:
            refIdent = new ReferenceIdent(new RelationName(parts[0], parts[1]), parts[2], nestedParts);
            break;
        default:
            throw new IllegalArgumentException("fqColumnName must contain <table>.<column> or <schema>.<table>.<column>");
    }
    return new Reference(refIdent, rowGranularity, dataType, 0, null);
}
Also used : Reference(io.crate.metadata.Reference) RelationName(io.crate.metadata.RelationName) ReferenceIdent(io.crate.metadata.ReferenceIdent)

Example 37 with RelationName

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

the class InputFactoryTest method prepare.

@Before
public void prepare() throws Exception {
    Map<RelationName, AnalyzedRelation> sources = T3.sources(List.of(T3.T1), clusterService);
    DocTableRelation tr1 = (DocTableRelation) sources.get(T3.T1);
    expressions = new SqlExpressions(sources, tr1);
    factory = new InputFactory(expressions.nodeCtx);
}
Also used : RelationName(io.crate.metadata.RelationName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 38 with RelationName

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

the class GroupByPlannerTest method testGroupByOrderByPartitionedClolumn.

@Test
public void testGroupByOrderByPartitionedClolumn() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addPartitionedTable("create table doc.clustered_parted (" + "   id integer," + "   date timestamp with time zone," + "   city string" + ") clustered by (city) partitioned by (date) ", new PartitionName(new RelationName("doc", "clustered_parted"), singletonList("1395874800000")).asIndexName(), new PartitionName(new RelationName("doc", "clustered_parted"), singletonList("1395961200000")).asIndexName()).build();
    Merge plan = e.plan("select date from clustered_parted group by date order by date");
    Merge reduceMerge = (Merge) plan.subPlan();
    OrderedTopNProjection topNProjection = (OrderedTopNProjection) reduceMerge.mergePhase().projections().get(1);
    Symbol orderBy = topNProjection.orderBy().get(0);
    assertThat(orderBy, instanceOf(InputColumn.class));
    assertThat(orderBy.valueType(), is(DataTypes.TIMESTAMPZ));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Merge(io.crate.planner.Merge) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) RelationName(io.crate.metadata.RelationName) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 39 with RelationName

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

the class DeletePartitionsTest method testIndexNameGeneration.

@Test
public void testIndexNameGeneration() throws Exception {
    SQLExecutor e = SQLExecutor.builder(clusterService).addPartitionedTable(TableDefinitions.PARTED_PKS_TABLE_DEFINITION, new PartitionName(new RelationName("doc", "parted_pks"), singletonList("1395874800000")).asIndexName(), new PartitionName(new RelationName("doc", "parted_pks"), singletonList("1395961200000")).asIndexName()).build();
    DeletePartitions plan = e.plan("delete from parted_pks where date = ?");
    Object[] args1 = { "1395874800000" };
    assertThat(plan.getIndices(txnCtx, e.nodeCtx, new RowN(args1), SubQueryResults.EMPTY), Matchers.containsInAnyOrder(".partitioned.parted_pks.04732cpp6ks3ed1o60o30c1g"));
    Object[] args2 = { "1395961200000" };
    assertThat(plan.getIndices(txnCtx, e.nodeCtx, new RowN(args2), SubQueryResults.EMPTY), Matchers.containsInAnyOrder(".partitioned.parted_pks.04732cpp6ksjcc9i60o30c1g"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) RowN(io.crate.data.RowN) SQLExecutor(io.crate.testing.SQLExecutor) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 40 with RelationName

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

the class RestoreSnapshotPlanTest method testResolvePartitionedTableIndexFromSnapshot.

@Test
public void testResolvePartitionedTableIndexFromSnapshot() {
    var context = new RestoreSnapshotPlan.ResolveIndicesAndTemplatesContext();
    RestoreSnapshotPlan.resolveTableFromSnapshots(new BoundRestoreSnapshot.RestoreTableInfo(new RelationName(Schemas.DOC_SCHEMA_NAME, "restoreme"), null), List.of(new SnapshotInfo(new SnapshotId("snapshot01", UUID.randomUUID().toString()), List.of(".partitioned.restoreme.046jcchm6krj4e1g60o30c0"), 0L, false)), context);
    String template = templateName(Schemas.DOC_SCHEMA_NAME, "restoreme");
    assertThat(context.resolvedIndices(), contains(template + "*"));
    assertThat(context.resolvedTemplates(), contains(template));
}
Also used : BoundRestoreSnapshot(io.crate.analyze.BoundRestoreSnapshot) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test)

Aggregations

RelationName (io.crate.metadata.RelationName)180 Test (org.junit.Test)100 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 PartitionName (io.crate.metadata.PartitionName)47 Symbol (io.crate.expression.symbol.Symbol)42 Reference (io.crate.metadata.Reference)37 ColumnIdent (io.crate.metadata.ColumnIdent)31 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)21 ReferenceIdent (io.crate.metadata.ReferenceIdent)21 DocTableInfo (io.crate.metadata.doc.DocTableInfo)21 Map (java.util.Map)20 HashMap (java.util.HashMap)19 SqlExpressions (io.crate.testing.SqlExpressions)18 ArrayList (java.util.ArrayList)18 List (java.util.List)17 Before (org.junit.Before)17 DocTableRelation (io.crate.analyze.relations.DocTableRelation)13 SQLExecutor (io.crate.testing.SQLExecutor)11 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)10