Search in sources :

Example 81 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTableIndexes.

@Test
public void testBuildCreateTableIndexes() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    Reference colA = new Reference(new ReferenceIdent(ident, "col_a", null), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.NOT_ANALYZED, true);
    Reference colB = new Reference(new ReferenceIdent(ident, "col_b", null), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.ANALYZED, true);
    Reference colC = new Reference(new ReferenceIdent(ident, "col_c", null), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.NO, true);
    Reference colD = new Reference(new ReferenceIdent(ident, "col_d", null), RowGranularity.DOC, DataTypes.OBJECT);
    Reference colE = new Reference(new ReferenceIdent(ident, "col_d", Arrays.asList("a")), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.NOT_ANALYZED, true);
    List<Reference> columns = ImmutableList.of(newReference(ident, "id", DataTypes.LONG), colA, colB, colC, colD, colE);
    ImmutableMap.Builder<ColumnIdent, IndexReference> indexBuilder = ImmutableMap.builder();
    indexBuilder.put(new ColumnIdent("col_a_col_b_ft"), new IndexReference(new ReferenceIdent(ident, "col_a_col_b_ft"), Reference.IndexType.ANALYZED, ImmutableList.of(colA, colB), "english")).put(new ColumnIdent("col_d_a_ft"), new IndexReference(new ReferenceIdent(ident, "col_d_a_ft"), Reference.IndexType.ANALYZED, ImmutableList.of(colE), "custom_analyzer"));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), indexBuilder.build(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.DYNAMIC);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" LONG,\n" + "   \"col_a\" STRING,\n" + "   \"col_b\" STRING INDEX USING FULLTEXT,\n" + "   \"col_c\" STRING INDEX OFF,\n" + "   \"col_d\" OBJECT (DYNAMIC) AS (\n" + "      \"a\" STRING\n" + "   ),\n" + "   INDEX \"col_a_col_b_ft\" USING FULLTEXT (\"col_a\", \"col_b\") WITH (\n" + "      analyzer = 'english'\n" + "   ),\n" + "   INDEX \"col_d_a_ft\" USING FULLTEXT (\"col_d\"['a']) WITH (\n" + "      analyzer = 'custom_analyzer'\n" + "   )\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'dynamic',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 82 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTableNotNull.

@Test
public void testBuildCreateTableNotNull() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    Reference colA = new Reference(new ReferenceIdent(ident, "col_a", null), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.NOT_ANALYZED, true);
    Reference colB = new Reference(new ReferenceIdent(ident, "col_b", null), RowGranularity.DOC, DataTypes.STRING, null, Reference.IndexType.ANALYZED, false);
    List<Reference> columns = ImmutableList.of(colA, colB);
    List<ColumnIdent> primaryKeys = ImmutableList.of(new ColumnIdent("col_a"));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), primaryKeys, null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.STRICT);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"col_a\" STRING,\n" + "   \"col_b\" STRING NOT NULL INDEX USING FULLTEXT,\n" + "   PRIMARY KEY (\"col_a\")\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'strict',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 83 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class MetaDataToASTNodeResolverTest method testBuildCreateTableClusteredByPartitionedBy.

@Test
public void testBuildCreateTableClusteredByPartitionedBy() throws Exception {
    TableIdent ident = new TableIdent("myschema", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "id", DataTypes.LONG), newReference(ident, "partition_column", DataTypes.STRING, null, null, true), newReference(ident, "cluster_column", DataTypes.STRING));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.of(columns.get(1)), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), new ColumnIdent("cluster_column"), ImmutableMap.<String, Object>of(), ImmutableList.of(columns.get(1).ident().columnIdent()), ColumnPolicy.DYNAMIC);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"myschema\".\"test\" (\n" + "   \"id\" LONG,\n" + "   \"partition_column\" STRING,\n" + "   \"cluster_column\" STRING\n" + ")\n" + "CLUSTERED BY (\"cluster_column\") INTO 5 SHARDS\n" + "PARTITIONED BY (\"partition_column\")\n" + "WITH (\n" + "   column_policy = 'dynamic',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 84 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class TransportShardUpsertAction method processRequestItems.

@Override
protected ShardResponse processRequestItems(ShardId shardId, ShardUpsertRequest request, AtomicBoolean killed) throws InterruptedException {
    ShardResponse shardResponse = new ShardResponse();
    DocTableInfo tableInfo = schemas.getWritableTable(TableIdent.fromIndexName(request.index()));
    IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
    IndexShard indexShard = indexService.shardSafe(shardId.id());
    Collection<ColumnIdent> notUsedNonGeneratedColumns = ImmutableList.of();
    if (request.validateConstraints()) {
        notUsedNonGeneratedColumns = getNotUsedNonGeneratedColumns(request.insertColumns(), tableInfo);
    }
    Translog.Location translogLocation = null;
    for (int i = 0; i < request.itemIndices().size(); i++) {
        int location = request.itemIndices().get(i);
        ShardUpsertRequest.Item item = request.items().get(i);
        if (killed.get()) {
            // set failure on response and skip all next items.
            // this way replica operation will be executed, but only items with a valid source (= was processed on primary)
            // will be processed on the replica
            shardResponse.failure(new InterruptedException());
            break;
        }
        try {
            translogLocation = indexItem(tableInfo, request, item, indexShard, // try insert first
            item.insertValues() != null, notUsedNonGeneratedColumns, 0);
            shardResponse.add(location);
        } catch (Throwable t) {
            if (retryPrimaryException(t)) {
                Throwables.propagate(t);
            }
            logger.debug("{} failed to execute upsert for [{}]/[{}]", t, request.shardId(), request.type(), item.id());
            // *mark* the item as failed by setting the source to null
            // to prevent the replica operation from processing this concrete item
            item.source(null);
            if (!request.continueOnError()) {
                shardResponse.failure(t);
                break;
            }
            shardResponse.add(location, new ShardResponse.Failure(item.id(), ExceptionsHelper.detailedMessage(t), (t instanceof VersionConflictEngineException)));
        }
    }
    if (indexShard.getTranslogDurability() == Translog.Durabilty.REQUEST && translogLocation != null) {
        indexShard.sync(translogLocation);
    }
    return shardResponse;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) Translog(org.elasticsearch.index.translog.Translog)

Example 85 with DocTableInfo

use of io.crate.metadata.doc.DocTableInfo in project crate by crate.

the class RefreshTableAnalyzer method getIndexNames.

private static Set<String> getIndexNames(List<Table> tables, Schemas schemas, ParameterContext parameterContext, @Nullable String defaultSchema) {
    Set<String> indexNames = new HashSet<>(tables.size());
    for (Table nodeTable : tables) {
        TableInfo tableInfo = schemas.getTableInfo(TableIdent.of(nodeTable, defaultSchema));
        Preconditions.checkArgument(tableInfo instanceof DocTableInfo, "operation cannot be performed on system and blob tables: table '%s'", tableInfo.ident().fqn());
        indexNames.addAll(TableAnalyzer.filteredIndices(parameterContext, nodeTable.partitionProperties(), (DocTableInfo) tableInfo));
    }
    return indexNames;
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) Table(io.crate.sql.tree.Table) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) HashSet(java.util.HashSet)

Aggregations

DocTableInfo (io.crate.metadata.doc.DocTableInfo)127 Test (org.junit.Test)56 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)40 Symbol (io.crate.expression.symbol.Symbol)27 Reference (io.crate.metadata.Reference)27 SQLExecutor (io.crate.testing.SQLExecutor)25 RelationName (io.crate.metadata.RelationName)24 DocTableRelation (io.crate.analyze.relations.DocTableRelation)20 ColumnIdent (io.crate.metadata.ColumnIdent)20 TableInfo (io.crate.metadata.table.TableInfo)18 Assignments (io.crate.expression.symbol.Assignments)16 Row (io.crate.data.Row)14 PlannerContext (io.crate.planner.PlannerContext)13 Before (org.junit.Before)13 RowConsumer (io.crate.data.RowConsumer)12 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)12 PartitionName (io.crate.metadata.PartitionName)12 DependencyCarrier (io.crate.planner.DependencyCarrier)12 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12