Search in sources :

Example 41 with RelationName

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

the class RestoreSnapshotPlanTest method testResolveMultiTablesIndexNamesFromSnapshot.

@Test
public void testResolveMultiTablesIndexNamesFromSnapshot() {
    List<BoundRestoreSnapshot.RestoreTableInfo> tables = List.of(new BoundRestoreSnapshot.RestoreTableInfo(new RelationName(Schemas.DOC_SCHEMA_NAME, "my_table"), null), new BoundRestoreSnapshot.RestoreTableInfo(new RelationName(Schemas.DOC_SCHEMA_NAME, "my_partitioned_table"), null));
    List<SnapshotInfo> snapshots = List.of(new SnapshotInfo(new SnapshotId("snapshot01", UUID.randomUUID().toString()), List.of(".partitioned.my_partitioned_table.046jcchm6krj4e1g60o30c0"), 0, false), new SnapshotInfo(new SnapshotId("snapshot03", UUID.randomUUID().toString()), List.of("my_table"), 0, false));
    var context = new RestoreSnapshotPlan.ResolveIndicesAndTemplatesContext();
    RestoreSnapshotPlan.resolveTablesFromSnapshots(tables, snapshots, context);
    assertThat(context.resolvedIndices(), containsInAnyOrder("my_table", templateName(Schemas.DOC_SCHEMA_NAME, "my_partitioned_table") + "*"));
    assertThat(context.resolvedTemplates(), contains(templateName(Schemas.DOC_SCHEMA_NAME, "my_partitioned_table")));
}
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)

Example 42 with RelationName

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

the class RestoreSnapshotPlanTest method testResolveTableIndexFromSnapshot.

@Test
public void testResolveTableIndexFromSnapshot() {
    var context = new RestoreSnapshotPlan.ResolveIndicesAndTemplatesContext();
    RestoreSnapshotPlan.resolveTableFromSnapshots(new BoundRestoreSnapshot.RestoreTableInfo(new RelationName("custom", "restoreme"), null), List.of(new SnapshotInfo(new SnapshotId("snapshot01", UUID.randomUUID().toString()), List.of("custom.restoreme"), 0L, false)), context);
    assertThat(context.resolvedIndices(), contains("custom.restoreme"));
    assertThat(context.resolvedTemplates().size(), is(0));
}
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)

Example 43 with RelationName

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

the class RestoreSnapshotPlanTest method testResolveEmptyPartitionedTemplate.

@Test
public void testResolveEmptyPartitionedTemplate() {
    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(), 0L, false)), context);
    assertThat(context.resolvedIndices().size(), is(0));
    // If the snapshot doesn't contain any index which belongs to the table, it could be that the user
    // restores an empty partitioned table. For that case we attempt to restore the table template.
    assertThat(context.resolvedTemplates(), contains(templateName(Schemas.DOC_SCHEMA_NAME, "restoreme")));
}
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)

Example 44 with RelationName

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

the class HashJoinConditionSymbolsExtractorTest method testExtractFromNestedEqCondition.

@Test
public void testExtractFromNestedEqCondition() {
    Symbol joinCondition = sqlExpressions.asSymbol("t1.x > t2.y and t1.a = t2.b and not(t1.i = t2.i)");
    Map<RelationName, List<Symbol>> symbolsPerRelation = HashJoinConditionSymbolsExtractor.extract(joinCondition);
    assertThat(symbolsPerRelation.get(tr1.relationName()), contains(isReference("a")));
    assertThat(symbolsPerRelation.get(tr2.relationName()), contains(isReference("b")));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) List(java.util.List) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 45 with RelationName

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

the class HashJoinConditionSymbolsExtractorTest method testExtractRelationsOfFunctionsWithLiterals.

@Test
public void testExtractRelationsOfFunctionsWithLiterals() {
    Symbol joinCondition = sqlExpressions.asSymbol("t1.a = t2.b and t1.i + 1::int = t2.i and t2.y = 1::int + t1.i");
    Map<RelationName, List<Symbol>> symbolsPerRelation = HashJoinConditionSymbolsExtractor.extract(joinCondition);
    assertThat(symbolsPerRelation.get(tr1.relationName()), containsInAnyOrder(isReference("a"), isFunction(ArithmeticFunctions.Names.ADD, isReference("i"), isLiteral(1)), isFunction(ArithmeticFunctions.Names.ADD, isLiteral(1), isReference("i"))));
    assertThat(symbolsPerRelation.get(tr2.relationName()), containsInAnyOrder(isReference("b"), isReference("i"), isReference("y")));
}
Also used : Symbol(io.crate.expression.symbol.Symbol) RelationName(io.crate.metadata.RelationName) List(java.util.List) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

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