Search in sources :

Example 6 with Field

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);
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with Field

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));
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with Field

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"));
}
Also used : Field(io.crate.analyze.symbol.Field) DummyRelation(io.crate.testing.DummyRelation) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with Field

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);
}
Also used : Field(io.crate.analyze.symbol.Field) QualifiedName(io.crate.sql.tree.QualifiedName) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with Field

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);
    }
}
Also used : Field(io.crate.analyze.symbol.Field) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

Field (io.crate.analyze.symbol.Field)24 CrateUnitTest (io.crate.test.integration.CrateUnitTest)14 Test (org.junit.Test)14 DummyRelation (io.crate.testing.DummyRelation)10 QualifiedName (io.crate.sql.tree.QualifiedName)8 Symbol (io.crate.analyze.symbol.Symbol)3 FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)2 Function (io.crate.analyze.symbol.Function)2 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 SymbolMatchers.isField (io.crate.testing.SymbolMatchers.isField)2 SessionContext (io.crate.action.sql.SessionContext)1 Analysis (io.crate.analyze.Analysis)1 QuerySpec (io.crate.analyze.QuerySpec)1 RelationSource (io.crate.analyze.RelationSource)1 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)1 TableRelation (io.crate.analyze.relations.TableRelation)1 AmbiguousColumnException (io.crate.exceptions.AmbiguousColumnException)1 TableInfo (io.crate.metadata.table.TableInfo)1 PGType (io.crate.protocols.postgres.types.PGType)1