Search in sources :

Example 31 with TableIdent

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

the class OptimizeTableAnalyzerTest method init.

@Before
public void init() throws Exception {
    TableIdent myBlobsIdent = new TableIdent(BlobSchemaInfo.NAME, "blobs");
    NoopClusterService clusterService = new NoopClusterService();
    TestingBlobTableInfo myBlobsTableInfo = TableDefinitions.createBlobTable(myBlobsIdent, clusterService);
    e = SQLExecutor.builder(clusterService).enableDefaultTables().addBlobTable(myBlobsTableInfo).build();
}
Also used : TableIdent(io.crate.metadata.TableIdent) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 32 with TableIdent

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

the class TableStatsServiceTest method testRowsToTableStatConversion.

@Test
public void testRowsToTableStatConversion() throws InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<ObjectLongMap<TableIdent>> statsFuture = new CompletableFuture<>();
    TableStatsService.TableStatsResultReceiver receiver = new TableStatsService.TableStatsResultReceiver(statsFuture::complete);
    receiver.setNextRow(new RowN(new Object[] { 1L, "custom", "foo" }));
    receiver.setNextRow(new RowN(new Object[] { 2L, "doc", "foo" }));
    receiver.setNextRow(new RowN(new Object[] { 3L, "bar", "foo" }));
    receiver.allFinished(false);
    ObjectLongMap<TableIdent> stats = statsFuture.get(10, TimeUnit.SECONDS);
    assertThat(stats.size(), is(3));
    assertThat(stats.get(new TableIdent("bar", "foo")), is(3L));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RowN(io.crate.data.RowN) TableIdent(io.crate.metadata.TableIdent) ObjectLongMap(com.carrotsearch.hppc.ObjectLongMap) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 33 with TableIdent

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

the class FetchPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    TableIdent t1 = new TableIdent(null, "t1");
    TreeMap<String, Integer> bases = new TreeMap<String, Integer>();
    bases.put(t1.name(), 0);
    bases.put("i2", 1);
    Multimap<TableIdent, String> tableIndices = HashMultimap.create();
    tableIndices.put(t1, t1.name());
    tableIndices.put(new TableIdent(null, "i2"), "i2_s1");
    tableIndices.put(new TableIdent(null, "i2"), "i2_s2");
    ReferenceIdent nameIdent = new ReferenceIdent(t1, "name");
    Reference name = new Reference(nameIdent, RowGranularity.DOC, DataTypes.STRING);
    FetchPhase orig = new FetchPhase(1, ImmutableSet.<String>of("node1", "node2"), bases, tableIndices, ImmutableList.of(name));
    BytesStreamOutput out = new BytesStreamOutput();
    ExecutionPhases.toStream(out, orig);
    StreamInput in = StreamInput.wrap(out.bytes());
    FetchPhase streamed = (FetchPhase) ExecutionPhases.fromStream(in);
    assertThat(orig.phaseId(), is(streamed.phaseId()));
    assertThat(orig.nodeIds(), is(streamed.nodeIds()));
    assertThat(orig.fetchRefs(), is(streamed.fetchRefs()));
    assertThat(orig.bases(), is(streamed.bases()));
    assertThat(orig.tableIndices(), is(streamed.tableIndices()));
}
Also used : Reference(io.crate.metadata.Reference) StreamInput(org.elasticsearch.common.io.stream.StreamInput) TableIdent(io.crate.metadata.TableIdent) TreeMap(java.util.TreeMap) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) ReferenceIdent(io.crate.metadata.ReferenceIdent) Test(org.junit.Test)

Example 34 with TableIdent

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

the class AlterTableOperation method executeAlterTableAddColumn.

public CompletableFuture<Long> executeAlterTableAddColumn(final AddColumnAnalyzedStatement analysis) {
    final CompletableFuture<Long> result = new CompletableFuture<>();
    if (analysis.newPrimaryKeys() || analysis.hasNewGeneratedColumns()) {
        TableIdent ident = analysis.table().ident();
        String stmt = String.format(Locale.ENGLISH, "SELECT COUNT(*) FROM \"%s\".\"%s\"", ident.schema(), ident.name());
        SQLOperations.SQLDirectExecutor sqlDirectExecutor = sqlOperations.createSQLDirectExecutor(ident.schema(), SQLOperations.Session.UNNAMED, stmt, 1);
        try {
            sqlDirectExecutor.execute(new ResultSetReceiver(analysis, result), Collections.emptyList());
        } catch (Throwable t) {
            result.completeExceptionally(t);
        }
    } else {
        addColumnToTable(analysis, result);
    }
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) TableIdent(io.crate.metadata.TableIdent) SQLOperations(io.crate.action.sql.SQLOperations)

Example 35 with TableIdent

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

the class FetchPhase method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeVInt(executionPhaseId);
    out.writeVInt(executionNodes.size());
    for (String executionNode : executionNodes) {
        out.writeString(executionNode);
    }
    out.writeVInt(bases.size());
    for (Map.Entry<String, Integer> entry : bases.entrySet()) {
        out.writeString(entry.getKey());
        out.writeVInt(entry.getValue());
    }
    out.writeVInt(fetchRefs.size());
    for (Reference ref : fetchRefs) {
        Reference.toStream(ref, out);
    }
    Map<TableIdent, Collection<String>> map = tableIndices.asMap();
    out.writeVInt(map.size());
    for (Map.Entry<TableIdent, Collection<String>> entry : map.entrySet()) {
        entry.getKey().writeTo(out);
        out.writeVInt(entry.getValue().size());
        for (String s : entry.getValue()) {
            out.writeString(s);
        }
    }
}
Also used : Reference(io.crate.metadata.Reference) TableIdent(io.crate.metadata.TableIdent)

Aggregations

TableIdent (io.crate.metadata.TableIdent)41 Test (org.junit.Test)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)15 PartitionName (io.crate.metadata.PartitionName)8 NoopClusterService (org.elasticsearch.test.cluster.NoopClusterService)7 Before (org.junit.Before)7 Reference (io.crate.metadata.Reference)6 DocTableInfo (io.crate.metadata.doc.DocTableInfo)6 List (java.util.List)5 Routing (io.crate.metadata.Routing)4 QualifiedName (io.crate.sql.tree.QualifiedName)4 BytesRef (org.apache.lucene.util.BytesRef)4 TableRelation (io.crate.analyze.relations.TableRelation)3 ReferenceIdent (io.crate.metadata.ReferenceIdent)3 TestingTableInfo (io.crate.metadata.table.TestingTableInfo)3 SqlExpressions (io.crate.testing.SqlExpressions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 IntObjectHashMap (com.carrotsearch.hppc.IntObjectHashMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 SharedShardContexts (io.crate.action.job.SharedShardContexts)2