Search in sources :

Example 16 with DrillPBError

use of org.apache.drill.exec.proto.UserBitShared.DrillPBError in project drill by axbaretto.

the class PlanSplitter method planFragments.

/**
 * Method to plan the query and return list of fragments
 * it will return query plan "as is" or split plans based on the req setting: split_plan
 * @param dContext
 * @param queryId
 * @param req
 * @param connection
 * @return
 */
@SuppressWarnings("resource")
public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId, GetQueryPlanFragments req, UserClientConnection connection) {
    QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
    final QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
    responseBuilder.setQueryId(queryId);
    try {
        responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
        responseBuilder.setStatus(QueryState.COMPLETED);
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with " + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
        DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
        responseBuilder.setStatus(QueryState.FAILED);
        responseBuilder.setError(error);
    }
    try {
        queryContext.close();
    } catch (Exception e) {
        logger.error("Error closing QueryContext when getting plan fragments for query {}.", QueryIdHelper.getQueryId(queryId), e);
    }
    return responseBuilder.build();
}
Also used : DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryContext(org.apache.drill.exec.ops.QueryContext)

Example 17 with DrillPBError

use of org.apache.drill.exec.proto.UserBitShared.DrillPBError in project drill by axbaretto.

the class TestDrillbitResilience method assertDrillbitsOk.

/**
 * Check that all the drillbits are ok.
 * <p/>
 * <p>The current implementation does this by counting the number of drillbits using a query.
 */
private static void assertDrillbitsOk() {
    final SingleRowListener listener = new SingleRowListener() {

        private final BufferAllocator bufferAllocator = RootAllocatorFactory.newRoot(zkHelper.getConfig());

        private final RecordBatchLoader loader = new RecordBatchLoader(bufferAllocator);

        @Override
        public void rowArrived(final QueryDataBatch queryResultBatch) {
            // load the single record
            final QueryData queryData = queryResultBatch.getHeader();
            try {
                loader.load(queryData.getDef(), queryResultBatch.getData());
            // TODO:  Clean:  DRILL-2933:  That load(...) no longer throws
            // SchemaChangeException, so check/clean catch clause below.
            } catch (final SchemaChangeException e) {
                fail(e.toString());
            }
            assertEquals(1, loader.getRecordCount());
            // there should only be one column
            final BatchSchema batchSchema = loader.getSchema();
            assertEquals(1, batchSchema.getFieldCount());
            // the column should be an integer
            final MaterializedField countField = batchSchema.getColumn(0);
            final MinorType fieldType = countField.getType().getMinorType();
            assertEquals(MinorType.BIGINT, fieldType);
            // get the column value
            final VectorWrapper<?> vw = loader.iterator().next();
            final Object obj = vw.getValueVector().getAccessor().getObject(0);
            assertTrue(obj instanceof Long);
            final Long countValue = (Long) obj;
            // assume this means all the drillbits are still ok
            assertEquals(drillbits.size(), countValue.intValue());
            loader.clear();
        }

        @Override
        public void cleanup() {
            DrillAutoCloseables.closeNoChecked(bufferAllocator);
        }
    };
    try {
        QueryTestUtil.testWithListener(drillClient, QueryType.SQL, "select count(*) from sys.memory", listener);
        listener.waitForCompletion();
        final QueryState state = listener.getQueryState();
        assertTrue(String.format("QueryState should be COMPLETED (and not %s).", state), state == QueryState.COMPLETED);
    } catch (final Exception e) {
        throw new RuntimeException("Couldn't query active drillbits", e);
    }
    final List<DrillPBError> errorList = listener.getErrorList();
    assertTrue("There should not be any errors when checking if Drillbits are OK.", errorList.isEmpty());
}
Also used : SingleRowListener(org.apache.drill.SingleRowListener) DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryData(org.apache.drill.exec.proto.UserBitShared.QueryData) RecordBatchLoader(org.apache.drill.exec.record.RecordBatchLoader) MaterializedField(org.apache.drill.exec.record.MaterializedField) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) DrillbitStartupException(org.apache.drill.exec.exception.DrillbitStartupException) ForemanException(org.apache.drill.exec.work.foreman.ForemanException) IOException(java.io.IOException) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) QueryDataBatch(org.apache.drill.exec.rpc.user.QueryDataBatch) BatchSchema(org.apache.drill.exec.record.BatchSchema) MinorType(org.apache.drill.common.types.TypeProtos.MinorType)

Example 18 with DrillPBError

use of org.apache.drill.exec.proto.UserBitShared.DrillPBError in project drill by apache.

the class DrillMetaImpl method serverGetColumns.

private MetaResultSet serverGetColumns(String catalog, Pat schemaPattern, Pat tableNamePattern, Pat columnNamePattern) {
    final LikeFilter catalogNameFilter = newLikeFilter(quote(catalog));
    final LikeFilter schemaNameFilter = newLikeFilter(schemaPattern);
    final LikeFilter tableNameFilter = newLikeFilter(tableNamePattern);
    final LikeFilter columnNameFilter = newLikeFilter(columnNamePattern);
    return new MetadataAdapter<MetaColumn, GetColumnsResp, ColumnMetadata>(MetaColumn.class) {

        @Override
        protected RequestStatus getStatus(GetColumnsResp response) {
            return response.getStatus();
        }

        @Override
        protected DrillPBError getError(GetColumnsResp response) {
            return response.getError();
        }

        @Override
        protected List<ColumnMetadata> getResult(GetColumnsResp response) {
            return response.getColumnsList();
        }

        private int getDataType(ColumnMetadata value) {
            switch(value.getDataType()) {
                case "ARRAY":
                    return Types.ARRAY;
                case "BIGINT":
                    return Types.BIGINT;
                case "BINARY":
                    return Types.BINARY;
                case "BINARY LARGE OBJECT":
                    return Types.BLOB;
                case "BINARY VARYING":
                    return Types.VARBINARY;
                case "BIT":
                    return Types.BIT;
                case "BOOLEAN":
                    return Types.BOOLEAN;
                case "CHARACTER":
                    return Types.CHAR;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "CHARACTER LARGE OBJECT":
                    return Types.CLOB;
                case "CHARACTER VARYING":
                    return Types.VARCHAR;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "DATALINK":
                    return Types.DATALINK;
                case "DATE":
                    return Types.DATE;
                case "DECIMAL":
                    return Types.DECIMAL;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "DISTINCT":
                    return Types.DISTINCT;
                case "DOUBLE":
                case "DOUBLE PRECISION":
                    return Types.DOUBLE;
                case "FLOAT":
                    return Types.FLOAT;
                case "INTEGER":
                    return Types.INTEGER;
                case "INTERVAL":
                    return Types.OTHER;
                // Resolve: Not seen in Drill yet. Can it ever appear?:
                case "JAVA_OBJECT":
                    return Types.JAVA_OBJECT;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "LONGNVARCHAR":
                    return Types.LONGNVARCHAR;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "LONGVARBINARY":
                    return Types.LONGVARBINARY;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "LONGVARCHAR":
                    return Types.LONGVARCHAR;
                case "MAP":
                    return Types.OTHER;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "NATIONAL CHARACTER":
                    return Types.NCHAR;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "NATIONAL CHARACTER LARGE OBJECT":
                    return Types.NCLOB;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "NATIONAL CHARACTER VARYING":
                    return Types.NVARCHAR;
                // mapping.
                case "NULL":
                    return Types.NULL;
                // (No NUMERIC--Drill seems to map any to DECIMAL currently.)
                case "NUMERIC":
                    return Types.NUMERIC;
                // Resolve: Unexpectedly, has appeared in Drill. Should it?
                case "OTHER":
                    return Types.OTHER;
                case "REAL":
                    return Types.REAL;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "REF":
                    return Types.REF;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "ROWID":
                    return Types.ROWID;
                case "SMALLINT":
                    return Types.SMALLINT;
                // Resolve: Not seen in Drill yet. Can it appear?:
                case "SQLXML":
                    return Types.SQLXML;
                case "STRUCT":
                    return Types.STRUCT;
                case "TIME":
                    return Types.TIME;
                case "TIMESTAMP":
                    return Types.TIMESTAMP;
                case "TINYINT":
                    return Types.TINYINT;
                default:
                    return Types.OTHER;
            }
        }

        Integer getDecimalDigits(ColumnMetadata value) {
            switch(value.getDataType()) {
                case "TINYINT":
                case "SMALLINT":
                case "INTEGER":
                case "BIGINT":
                case "DECIMAL":
                case "NUMERIC":
                    return value.hasNumericScale() ? value.getNumericScale() : null;
                case "REAL":
                    return DECIMAL_DIGITS_REAL;
                case "FLOAT":
                    return DECIMAL_DIGITS_FLOAT;
                case "DOUBLE":
                    return DECIMAL_DIGITS_DOUBLE;
                case "DATE":
                case "TIME":
                case "TIMESTAMP":
                case "INTERVAL":
                    return value.getDateTimePrecision();
                default:
                    return null;
            }
        }

        private Integer getNumPrecRadix(ColumnMetadata value) {
            switch(value.getDataType()) {
                case "TINYINT":
                case "SMALLINT":
                case "INTEGER":
                case "BIGINT":
                case "DECIMAL":
                case "NUMERIC":
                case "REAL":
                case "FLOAT":
                case "DOUBLE":
                    return value.getNumericPrecisionRadix();
                case "INTERVAL":
                    return RADIX_INTERVAL;
                case "DATE":
                case "TIME":
                case "TIMESTAMP":
                    return RADIX_DATETIME;
                default:
                    return null;
            }
        }

        private int getNullable(ColumnMetadata value) {
            if (!value.hasIsNullable()) {
                return DatabaseMetaData.columnNullableUnknown;
            }
            return value.getIsNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls;
        }

        private String getIsNullable(ColumnMetadata value) {
            if (!value.hasIsNullable()) {
                return "";
            }
            return value.getIsNullable() ? "YES" : "NO";
        }

        private Integer getCharOctetLength(ColumnMetadata value) {
            if (!value.hasCharMaxLength()) {
                return null;
            }
            switch(value.getDataType()) {
                case "CHARACTER":
                case "CHARACTER LARGE OBJECT":
                case "CHARACTER VARYING":
                case "LONGVARCHAR":
                case "LONGNVARCHAR":
                case "NATIONAL CHARACTER":
                case "NATIONAL CHARACTER LARGE OBJECT":
                case "NATIONAL CHARACTER VARYING":
                    return value.getCharOctetLength();
                default:
                    return null;
            }
        }

        @Override
        protected MetaColumn adapt(ColumnMetadata value) {
            return new MetaColumn(value.getCatalogName(), value.getSchemaName(), value.getTableName(), value.getColumnName(), // It might require the full SQL type
            getDataType(value), value.getDataType(), value.getColumnSize(), getDecimalDigits(value), getNumPrecRadix(value), getNullable(value), getCharOctetLength(value), value.getOrdinalPosition(), getIsNullable(value));
        }
    }.getMeta(connection.getClient().getColumns(catalogNameFilter, schemaNameFilter, tableNameFilter, columnNameFilter));
}
Also used : LikeFilter(org.apache.drill.exec.proto.UserProtos.LikeFilter) GetColumnsResp(org.apache.drill.exec.proto.UserProtos.GetColumnsResp) ColumnMetadata(org.apache.drill.exec.proto.UserProtos.ColumnMetadata) DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) ArrayList(java.util.ArrayList) List(java.util.List) RequestStatus(org.apache.drill.exec.proto.UserProtos.RequestStatus)

Example 19 with DrillPBError

use of org.apache.drill.exec.proto.UserBitShared.DrillPBError in project drill by apache.

the class PlanSplitter method planFragments.

/**
 * Method to plan the query and return list of fragments
 * it will return query plan "as is" or split plans based on the req setting: split_plan
 * @param dContext
 * @param queryId
 * @param req
 * @param connection
 * @return
 */
public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId, GetQueryPlanFragments req, UserClientConnection connection) {
    QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
    final QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
    responseBuilder.setQueryId(queryId);
    try {
        responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
        responseBuilder.setStatus(QueryState.COMPLETED);
    } catch (Exception e) {
        final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with " + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
        DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
        responseBuilder.setStatus(QueryState.FAILED);
        responseBuilder.setError(error);
    }
    try {
        queryContext.close();
    } catch (Exception e) {
        logger.error("Error closing QueryContext when getting plan fragments for query {}.", QueryIdHelper.getQueryId(queryId), e);
    }
    return responseBuilder.build();
}
Also used : DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) QueryPlanFragments(org.apache.drill.exec.proto.UserProtos.QueryPlanFragments) GetQueryPlanFragments(org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments) QueryContext(org.apache.drill.exec.ops.QueryContext)

Example 20 with DrillPBError

use of org.apache.drill.exec.proto.UserBitShared.DrillPBError in project drill by apache.

the class TestUserException method testBuildUserExceptionWithMessage.

@Test
public void testBuildUserExceptionWithMessage() {
    String message = "Test message";
    UserException uex = UserException.dataWriteError().message(message).build(logger);
    DrillPBError error = uex.getOrCreatePBError(false);
    Assert.assertEquals(ErrorType.DATA_WRITE, error.getErrorType());
    Assert.assertEquals(message, uex.getOriginalMessage());
}
Also used : DrillPBError(org.apache.drill.exec.proto.UserBitShared.DrillPBError) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Aggregations

DrillPBError (org.apache.drill.exec.proto.UserBitShared.DrillPBError)23 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)6 List (java.util.List)6 LikeFilter (org.apache.drill.exec.proto.UserProtos.LikeFilter)6 RequestStatus (org.apache.drill.exec.proto.UserProtos.RequestStatus)6 BaseTest (org.apache.drill.test.BaseTest)6 MetaImpl (org.apache.calcite.avatica.MetaImpl)4 SQLException (java.sql.SQLException)2 ExecutionException (java.util.concurrent.ExecutionException)2 QueryContext (org.apache.drill.exec.ops.QueryContext)2 ColumnMetadata (org.apache.drill.exec.proto.UserProtos.ColumnMetadata)2 GetColumnsResp (org.apache.drill.exec.proto.UserProtos.GetColumnsResp)2 GetQueryPlanFragments (org.apache.drill.exec.proto.UserProtos.GetQueryPlanFragments)2 GetSchemasResp (org.apache.drill.exec.proto.UserProtos.GetSchemasResp)2 GetServerMetaResp (org.apache.drill.exec.proto.UserProtos.GetServerMetaResp)2 GetTablesResp (org.apache.drill.exec.proto.UserProtos.GetTablesResp)2 QueryPlanFragments (org.apache.drill.exec.proto.UserProtos.QueryPlanFragments)2 SchemaMetadata (org.apache.drill.exec.proto.UserProtos.SchemaMetadata)2 TableMetadata (org.apache.drill.exec.proto.UserProtos.TableMetadata)2