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