Search in sources :

Example 86 with RelationName

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

the class CopyAnalyzerTest method testCopyToWithPartitionIdentAndPartitionInWhereClause.

@Test
public void testCopyToWithPartitionIdentAndPartitionInWhereClause() throws Exception {
    BoundCopyTo analysis = analyze("COPY parted PARTITION (date=1395874800000) WHERE date = 1395874800000 TO DIRECTORY '/tmp/foo'");
    String parted = new PartitionName(new RelationName("doc", "parted"), Collections.singletonList("1395874800000")).asIndexName();
    assertThat(analysis.whereClause().partitions(), contains(parted));
}
Also used : PartitionName(io.crate.metadata.PartitionName) RelationName(io.crate.metadata.RelationName) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 87 with RelationName

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

the class CreateViewAnalyzerTest method testCreateViewCreatesViewInDefaultSchema.

@Test
public void testCreateViewCreatesViewInDefaultSchema() {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).setSearchPath("firstSchema", "secondSchema").build();
    CreateViewStmt createView = sqlExecutor.analyze("create view v1 as select * from sys.nodes");
    assertThat(createView.name(), is(new RelationName(sqlExecutor.getSessionContext().searchPath().currentSchema(), "v1")));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) RelationName(io.crate.metadata.RelationName) InvalidRelationName(io.crate.exceptions.InvalidRelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 88 with RelationName

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

the class PartitionPropertiesAnalyzerTest method testPartitionNameFromAssignmentWithBytesRef.

@Test
public void testPartitionNameFromAssignmentWithBytesRef() {
    DocTableInfo tableInfo = SQLExecutor.partitionedTableInfo(new RelationName("doc", "users"), "create table doc.users (name text primary key) partitioned by (name)", clusterService);
    PartitionName partitionName = getPartitionName(tableInfo);
    assertThat(partitionName.values(), Matchers.contains("foo"));
    assertThat(partitionName.asIndexName(), is(".partitioned.users.0426crrf"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 89 with RelationName

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

the class PartitionPropertiesAnalyzerTest method testPartitionNameOnRegularTable.

@Test
public void testPartitionNameOnRegularTable() {
    DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName("doc", "users"), "create table doc.users (name text primary key)", clusterService);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("table 'doc.users' is not partitioned");
    getPartitionName(tableInfo);
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) RelationName(io.crate.metadata.RelationName) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 90 with RelationName

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

the class CommonQueryBuilderTest method testWhereRefEqNullWithDifferentTypes.

@Test
public void testWhereRefEqNullWithDifferentTypes() throws Exception {
    for (DataType<?> type : DataTypes.PRIMITIVE_TYPES) {
        if (type.storageSupport() == null) {
            continue;
        }
        // ensure the test is operating on a fresh, empty cluster state (no existing tables)
        resetClusterService();
        DocTableInfo tableInfo = SQLExecutor.tableInfo(new RelationName(DocSchemaInfo.NAME, "test_primitive"), "create table doc.test_primitive (" + "  x " + type.getName() + ")", clusterService);
        TableRelation tableRelation = new TableRelation(tableInfo);
        Map<RelationName, AnalyzedRelation> tableSources = Map.of(tableInfo.ident(), tableRelation);
        SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation, User.CRATE_USER);
        Query query = convert(sqlExpressions.normalize(sqlExpressions.asSymbol("x = null")));
        // must always become a MatchNoDocsQuery
        // string: term query with null would cause NPE
        // int/numeric: rangeQuery from null to null would match all
        // bool:  term would match false too because of the condition in the eq query builder
        assertThat(query, instanceOf(MatchNoDocsQuery.class));
    }
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PointInSetQuery(org.apache.lucene.search.PointInSetQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) RelationName(io.crate.metadata.RelationName) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) SqlExpressions(io.crate.testing.SqlExpressions) TableRelation(io.crate.analyze.relations.TableRelation) 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