Search in sources :

Example 91 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by axbaretto.

the class BaseRawBatchBuffer method getNext.

@Override
public RawFragmentBatch getNext() throws IOException {
    if (outOfMemory.get()) {
        if (bufferQueue.size() < 10) {
            outOfMemory.set(false);
        }
    }
    RawFragmentBatch b;
    try {
        b = bufferQueue.poll();
        // if we didn't get a batch, block on waiting for queue.
        if (b == null && (!isTerminated() || !bufferQueue.isEmpty())) {
            b = bufferQueue.take();
        }
    } catch (final InterruptedException e) {
        // We expect that the interrupt means the fragment is canceled or failed, so we should kill this buffer
        if (!context.getExecutorState().shouldContinue()) {
            kill(context);
        } else {
            throw new DrillRuntimeException("Interrupted but context.shouldContinue() is true", e);
        }
        // Preserve evidence that the interruption occurred so that code higher up on the call stack can learn of the
        // interruption and respond to it if it wants to.
        Thread.currentThread().interrupt();
        return null;
    }
    if (context.getAllocator().isOverLimit()) {
        outOfMemory.set(true);
    }
    if (b != null) {
        upkeep(b);
        if (b.getHeader().getIsLastBatch()) {
            logger.debug("Got last batch from {}:{}", b.getHeader().getSendingMajorFragmentId(), b.getHeader().getSendingMinorFragmentId());
            final int remainingStreams = decrementStreamCounter();
            if (remainingStreams == 0) {
                logger.debug("Streams finished");
                allStreamsFinished();
            }
        }
    } else {
        if (!bufferQueue.isEmpty()) {
            throw new IllegalStateException("Returning null when there are batches left in queue");
        }
        if (!isTerminated()) {
            throw new IllegalStateException("Returning null when not finished");
        }
    }
    assertAckSent(b);
    return b;
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 92 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by axbaretto.

the class TestExternalSortExec method testOrdering.

@Test
public void testOrdering() {
    assertEquals(Direction.ASCENDING, Ordering.getOrderingSpecFromString(null));
    assertEquals(Direction.ASCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_ASC));
    assertEquals(Direction.DESCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_DESC));
    assertEquals(Direction.ASCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_ASCENDING));
    assertEquals(Direction.DESCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_DESCENDING));
    assertEquals(Direction.ASCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_ASC.toLowerCase()));
    assertEquals(Direction.DESCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_DESC.toLowerCase()));
    assertEquals(Direction.ASCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_ASCENDING.toLowerCase()));
    assertEquals(Direction.DESCENDING, Ordering.getOrderingSpecFromString(Ordering.ORDER_DESCENDING.toLowerCase()));
    try {
        Ordering.getOrderingSpecFromString("");
        fail();
    } catch (DrillRuntimeException e) {
    }
    try {
        Ordering.getOrderingSpecFromString("foo");
        fail();
    } catch (DrillRuntimeException e) {
    }
    assertEquals(NullDirection.UNSPECIFIED, Ordering.getNullOrderingFromString(null));
    assertEquals(NullDirection.FIRST, Ordering.getNullOrderingFromString(Ordering.NULLS_FIRST));
    assertEquals(NullDirection.LAST, Ordering.getNullOrderingFromString(Ordering.NULLS_LAST));
    assertEquals(NullDirection.UNSPECIFIED, Ordering.getNullOrderingFromString(Ordering.NULLS_UNSPECIFIED));
    assertEquals(NullDirection.FIRST, Ordering.getNullOrderingFromString(Ordering.NULLS_FIRST.toLowerCase()));
    assertEquals(NullDirection.LAST, Ordering.getNullOrderingFromString(Ordering.NULLS_LAST.toLowerCase()));
    assertEquals(NullDirection.UNSPECIFIED, Ordering.getNullOrderingFromString(Ordering.NULLS_UNSPECIFIED.toLowerCase()));
    try {
        Ordering.getNullOrderingFromString("");
        fail();
    } catch (DrillRuntimeException e) {
    }
    try {
        Ordering.getNullOrderingFromString("foo");
        fail();
    } catch (DrillRuntimeException e) {
    }
    FieldReference expr = FieldReference.getWithQuotedRef("foo");
    // Test all getters
    Ordering ordering = new Ordering((String) null, expr, (String) null);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    assertSame(expr, ordering.getExpr());
    assertTrue(ordering.nullsSortHigh());
    // Test all ordering strings
    ordering = new Ordering((String) Ordering.ORDER_ASC, expr, (String) null);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    ordering = new Ordering((String) Ordering.ORDER_ASC.toLowerCase(), expr, (String) null);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    ordering = new Ordering((String) Ordering.ORDER_ASCENDING, expr, (String) null);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    ordering = new Ordering((String) Ordering.ORDER_DESC, expr, (String) null);
    assertEquals(Direction.DESCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    ordering = new Ordering((String) Ordering.ORDER_DESCENDING, expr, (String) null);
    assertEquals(Direction.DESCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    // Test all null ordering strings
    ordering = new Ordering((String) null, expr, Ordering.NULLS_FIRST);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.FIRST, ordering.getNullDirection());
    assertFalse(ordering.nullsSortHigh());
    ordering = new Ordering((String) null, expr, Ordering.NULLS_FIRST);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.FIRST, ordering.getNullDirection());
    assertFalse(ordering.nullsSortHigh());
    ordering = new Ordering((String) null, expr, Ordering.NULLS_LAST);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.LAST, ordering.getNullDirection());
    assertTrue(ordering.nullsSortHigh());
    ordering = new Ordering((String) null, expr, Ordering.NULLS_UNSPECIFIED);
    assertEquals(Direction.ASCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    assertTrue(ordering.nullsSortHigh());
    // Unspecified order is always nulls high
    ordering = new Ordering(Ordering.ORDER_DESC, expr, Ordering.NULLS_UNSPECIFIED);
    assertEquals(Direction.DESCENDING, ordering.getDirection());
    assertEquals(NullDirection.UNSPECIFIED, ordering.getNullDirection());
    assertTrue(ordering.nullsSortHigh());
    // Null sort direction reverses with a Desc sort.
    ordering = new Ordering(Ordering.ORDER_DESC, expr, Ordering.NULLS_FIRST);
    assertEquals(Direction.DESCENDING, ordering.getDirection());
    assertEquals(NullDirection.FIRST, ordering.getNullDirection());
    assertTrue(ordering.nullsSortHigh());
    ordering = new Ordering(Ordering.ORDER_DESC, expr, Ordering.NULLS_LAST);
    assertEquals(Direction.DESCENDING, ordering.getDirection());
    assertEquals(NullDirection.LAST, ordering.getNullDirection());
    assertFalse(ordering.nullsSortHigh());
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) Ordering(org.apache.drill.common.logical.data.Order.Ordering) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 93 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by axbaretto.

the class DrillMetaImpl method s.

private MetaResultSet s(String s) {
    try {
        logger.debug("Running {}", s);
        AvaticaStatement statement = connection.createStatement();
        return MetaResultSet.create(connection.id, statement.getId(), true, newSignature(s), null);
    } catch (Exception e) {
        // didn't allow for SQLException!
        throw new DrillRuntimeException("Failure while attempting to get DatabaseMetadata.", e);
    }
}
Also used : DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) RpcException(org.apache.drill.exec.rpc.RpcException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) SQLException(java.sql.SQLException) MissingResultsException(org.apache.calcite.avatica.MissingResultsException) NoSuchStatementException(org.apache.calcite.avatica.NoSuchStatementException) AvaticaStatement(org.apache.calcite.avatica.AvaticaStatement)

Example 94 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by axbaretto.

the class MetaImpl method s.

private ResultSet s(String s) {
    try {
        logger.debug("Running {}", s);
        AvaticaStatement statement = connection.createStatement();
        statement.execute(s);
        return statement.getResultSet();
    } catch (Exception e) {
        // didn't allow for SQLException!
        throw new DrillRuntimeException("Failure while attempting to get DatabaseMetadata.", e);
    }
}
Also used : DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) AvaticaStatement(net.hydromatic.avatica.AvaticaStatement)

Example 95 with DrillRuntimeException

use of org.apache.drill.common.exceptions.DrillRuntimeException in project drill by apache.

the class AvroRecordReader method processPrimitive.

private void processPrimitive(final Object value, final Schema.Type type, final String fieldName, final MapOrListWriterImpl writer) {
    if (value == null) {
        return;
    }
    switch(type) {
        case STRING:
            byte[] binary = null;
            final int length;
            if (value instanceof Utf8) {
                binary = ((Utf8) value).getBytes();
                length = ((Utf8) value).getByteLength();
            } else {
                binary = value.toString().getBytes(Charsets.UTF_8);
                length = binary.length;
            }
            ensure(length);
            buffer.setBytes(0, binary);
            writer.varChar(fieldName).writeVarChar(0, length, buffer);
            break;
        case INT:
            writer.integer(fieldName).writeInt((Integer) value);
            break;
        case LONG:
            writer.bigInt(fieldName).writeBigInt((Long) value);
            break;
        case FLOAT:
            writer.float4(fieldName).writeFloat4((Float) value);
            break;
        case DOUBLE:
            writer.float8(fieldName).writeFloat8((Double) value);
            break;
        case BOOLEAN:
            writer.bit(fieldName).writeBit((Boolean) value ? 1 : 0);
            break;
        case BYTES:
            final ByteBuffer buf = (ByteBuffer) value;
            length = buf.remaining();
            ensure(length);
            buffer.setBytes(0, buf);
            writer.binary(fieldName).writeVarBinary(0, length, buffer);
            break;
        case NULL:
            // Nothing to do for null type
            break;
        case ENUM:
            final String symbol = value.toString();
            final byte[] b;
            try {
                b = symbol.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new DrillRuntimeException("Unable to read enum value for field: " + fieldName, e);
            }
            ensure(b.length);
            buffer.setBytes(0, b);
            writer.varChar(fieldName).writeVarChar(0, b.length, buffer);
            break;
        default:
            throw new DrillRuntimeException("Unhandled Avro type: " + type.toString());
    }
}
Also used : Utf8(org.apache.avro.util.Utf8) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)184 IOException (java.io.IOException)76 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)18 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)15 UserException (org.apache.drill.common.exceptions.UserException)13 Path (org.apache.hadoop.fs.Path)13 KeeperException (org.apache.zookeeper.KeeperException)12 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)12 NoSuchElementException (java.util.NoSuchElementException)11 Stopwatch (com.google.common.base.Stopwatch)10 TypeProtos (org.apache.drill.common.types.TypeProtos)9 Bson (org.bson.conversions.Bson)9 MaterializedField (org.apache.drill.exec.record.MaterializedField)8 List (java.util.List)7 RexNode (org.apache.calcite.rex.RexNode)7 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)7 ValueHolder (org.apache.drill.exec.expr.holders.ValueHolder)6 VarCharHolder (org.apache.drill.exec.expr.holders.VarCharHolder)6 Registry (org.apache.drill.exec.proto.UserBitShared.Registry)6 Admin (org.apache.hadoop.hbase.client.Admin)6