Search in sources :

Example 11 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class LuceneReferenceResolver method typeSpecializedExpression.

private static LuceneCollectorExpression<?> typeSpecializedExpression(final FieldTypeLookup fieldTypeLookup, final Reference ref) {
    final String fqn = ref.column().fqn();
    final MappedFieldType fieldType = fieldTypeLookup.get(fqn);
    if (fieldType == null) {
        return NO_FIELD_TYPES_IDS.contains(unnest(ref.valueType()).id()) || isIgnoredDynamicReference(ref) ? DocCollectorExpression.create(toSourceLookup(ref)) : new LiteralValueExpression(null);
    }
    if (!fieldType.hasDocValues()) {
        return DocCollectorExpression.create(toSourceLookup(ref));
    }
    switch(ref.valueType().id()) {
        case BitStringType.ID:
            return new BitStringColumnReference(fqn, ((BitStringType) ref.valueType()).length());
        case ByteType.ID:
            return new ByteColumnReference(fqn);
        case ShortType.ID:
            return new ShortColumnReference(fqn);
        case IpType.ID:
            return new IpColumnReference(fqn);
        case StringType.ID:
            return new BytesRefColumnReference(fqn);
        case DoubleType.ID:
            return new DoubleColumnReference(fqn);
        case BooleanType.ID:
            return new BooleanColumnReference(fqn);
        case FloatType.ID:
            return new FloatColumnReference(fqn);
        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return new LongColumnReference(fqn);
        case IntegerType.ID:
            return new IntegerColumnReference(fqn);
        case GeoPointType.ID:
            return new GeoPointColumnReference(fqn);
        case ArrayType.ID:
            return DocCollectorExpression.create(toSourceLookup(ref));
        default:
            throw new UnhandledServerException("Unsupported type: " + ref.valueType().getName());
    }
}
Also used : MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) UnhandledServerException(io.crate.exceptions.UnhandledServerException)

Example 12 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class DocTableInfoBuilder method buildDocIndexMetadata.

private DocIndexMetadata buildDocIndexMetadata(String indexName) {
    DocIndexMetadata docIndexMetadata;
    IndexMetadata indexMetadata = metadata.index(indexName);
    try {
        docIndexMetadata = new DocIndexMetadata(nodeCtx, indexMetadata, ident);
    } catch (IOException e) {
        throw new UnhandledServerException("Unable to build DocIndexMetadata", e);
    }
    try {
        return docIndexMetadata.build();
    } catch (Exception e) {
        try {
            LOGGER.error("Could not build DocIndexMetadata from: {}", indexMetadata.mapping().getSourceAsMap());
        } catch (Exception ignored) {
        }
        throw e;
    }
}
Also used : UnhandledServerException(io.crate.exceptions.UnhandledServerException) IOException(java.io.IOException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) IOException(java.io.IOException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) UnhandledServerException(io.crate.exceptions.UnhandledServerException)

Example 13 with UnhandledServerException

use of io.crate.exceptions.UnhandledServerException in project crate by crate.

the class CountTaskTest method testClose.

@Test
public void testClose() throws Exception {
    CompletableFuture<Long> future = new CompletableFuture<>();
    CountOperation countOperation = mock(CountOperation.class);
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    CountTask countTask = new CountTask(countPhaseWithId(1), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.complete(1L);
    assertTrue(countTask.isClosed());
    // assure that there was no exception
    countTask.completionFuture().get();
    // on error
    future = new CompletableFuture<>();
    when(countOperation.count(eq(txnCtx), any(), any(Symbol.class))).thenReturn(future);
    countTask = new CountTask(countPhaseWithId(2), txnCtx, countOperation, new TestingRowConsumer(), null);
    countTask.start();
    future.completeExceptionally(new UnhandledServerException("dummy"));
    assertTrue(countTask.isClosed());
    expectedException.expectCause(CauseMatcher.cause(UnhandledServerException.class));
    countTask.completionFuture().get();
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Symbol(io.crate.expression.symbol.Symbol) UnhandledServerException(io.crate.exceptions.UnhandledServerException) CountOperation(io.crate.execution.engine.collect.count.CountOperation) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Test(org.junit.Test)

Aggregations

UnhandledServerException (io.crate.exceptions.UnhandledServerException)13 IOException (java.io.IOException)4 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 IllegalIndexShardStateException (org.elasticsearch.index.shard.IllegalIndexShardStateException)3 ShardId (org.elasticsearch.index.shard.ShardId)3 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)3 ResourceUnknownException (io.crate.exceptions.ResourceUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)2 Settings (org.elasticsearch.common.settings.Settings)2 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)2 Test (org.junit.Test)2 SharedShardContext (io.crate.action.job.SharedShardContext)1 SharedShardContexts (io.crate.action.job.SharedShardContexts)1 OrderBy (io.crate.analyze.OrderBy)1