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();
}
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));
}
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()));
}
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;
}
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);
}
}
}
Aggregations