use of io.crate.analyze.symbol.Field in project crate by crate.
the class FieldProviderTest method testSimpleResolverUnknownColumn.
@Test
public void testSimpleResolverUnknownColumn() throws Exception {
expectedException.expect(ColumnUnknownException.class);
expectedException.expectMessage("Column unknown unknown");
AnalyzedRelation relation = new DummyRelation("name");
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("doc.t"), relation));
resolver.resolveField(new QualifiedName(Arrays.asList("unknown")), Operation.READ);
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class FieldProviderTest method testSimpleFieldResolver.
@Test
public void testSimpleFieldResolver() throws Exception {
// select name from doc.t
AnalyzedRelation relation = new DummyRelation("name");
FieldProvider<Field> resolver = new NameFieldProvider(relation);
Field field = resolver.resolveField(new QualifiedName(Arrays.asList("name")), Operation.READ);
assertThat(field.relation(), equalTo(relation));
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class FieldProviderTest method testRelationOutputFromSingleColumnName.
@Test
public void testRelationOutputFromSingleColumnName() throws Exception {
// select name from t
AnalyzedRelation relation = new DummyRelation("name");
FieldProvider<Field> resolver = new FullQualifedNameFieldProvider(ImmutableMap.of(newQN("doc.t"), relation));
Field field = resolver.resolveField(newQN("name"), Operation.READ);
assertThat(field.relation(), equalTo(relation));
assertThat(field.path().outputName(), is("name"));
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class FieldProviderTest method testTooManyPartsNameFieldResolver.
@Test
public void testTooManyPartsNameFieldResolver() throws Exception {
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Column reference \"a.b\" has too many parts. A column must not have a schema or a table here.");
FieldProvider<Field> resolver = new NameFieldProvider(dummyRelation);
resolver.resolveField(new QualifiedName(Arrays.asList("a", "b")), Operation.READ);
}
use of io.crate.analyze.symbol.Field in project crate by crate.
the class RestSQLAction method executeBulkRequest.
private void executeBulkRequest(SQLXContentSourceContext context, final RestRequest request, final RestChannel channel) {
SQLOperations.Session session = sqlOperations.createSession(request.header(REQUEST_HEADER_SCHEMA), toOptions(request), DEFAULT_SOFT_LIMIT);
try {
final long startTime = System.nanoTime();
session.parse(UNNAMED, context.stmt(), Collections.<DataType>emptyList());
Object[][] bulkArgs = context.bulkArgs();
final RestBulkRowCountReceiver.Result[] results = new RestBulkRowCountReceiver.Result[bulkArgs.length];
if (results.length == 0) {
session.bind(UNNAMED, UNNAMED, Collections.emptyList(), null);
session.execute(UNNAMED, 0, new BaseResultReceiver());
} else {
for (int i = 0; i < bulkArgs.length; i++) {
session.bind(UNNAMED, UNNAMED, Arrays.asList(bulkArgs[i]), null);
ResultReceiver resultReceiver = new RestBulkRowCountReceiver(results, i);
session.execute(UNNAMED, 0, resultReceiver);
}
}
List<Field> outputColumns = session.describe('P', UNNAMED);
if (outputColumns != null) {
throw new UnsupportedOperationException("Bulk operations for statements that return result sets is not supported");
}
session.sync().whenComplete((Object result, Throwable t) -> {
if (t == null) {
try {
XContentBuilder builder = ResultToXContentBuilder.builder(channel).cols(Collections.<Field>emptyList()).duration(startTime).bulkRows(results).build();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
errorResponse(channel, e);
}
} else {
errorResponse(channel, t);
}
});
} catch (Throwable t) {
errorResponse(channel, t);
}
}
Aggregations