Search in sources :

Example 1 with VoltTypeException

use of org.voltdb.VoltTypeException in project voltdb by VoltDB.

the class PerPartitionTable method reinsertFailed.

private void reinsertFailed(List<VoltBulkLoaderRow> rows) throws Exception {
    VoltTable tmpTable = new VoltTable(m_columnInfo);
    for (final VoltBulkLoaderRow row : rows) {
        // previously successful.
        try {
            Object[] row_args = new Object[row.m_rowData.length];
            for (int i = 0; i < row_args.length; i++) {
                final VoltType type = m_columnTypes[i];
                row_args[i] = ParameterConverter.tryToMakeCompatible(type.classFromType(), row.m_rowData[i]);
            }
            tmpTable.addRow(row_args);
        } catch (VoltTypeException ex) {
            // should have caught this
            continue;
        }
        ProcedureCallback callback = new ProcedureCallback() {

            @Override
            public void clientCallback(ClientResponse response) throws Exception {
                row.m_loader.m_loaderCompletedCnt.incrementAndGet();
                row.m_loader.m_outstandingRowCount.decrementAndGet();
                //one insert at a time callback
                if (response.getStatus() != ClientResponse.SUCCESS) {
                    row.m_loader.m_notificationCallBack.failureCallback(row.m_rowHandle, row.m_rowData, response);
                }
            }
        };
        loadTable(callback, tmpTable);
    }
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) VoltType(org.voltdb.VoltType) VoltTypeException(org.voltdb.VoltTypeException) VoltTable(org.voltdb.VoltTable)

Example 2 with VoltTypeException

use of org.voltdb.VoltTypeException in project voltdb by VoltDB.

the class PerPartitionTable method buildTable.

private PartitionProcedureCallback buildTable() {
    ArrayList<VoltBulkLoaderRow> buf = new ArrayList<VoltBulkLoaderRow>(m_minBatchTriggerSize);
    m_partitionRowQueue.drainTo(buf, m_minBatchTriggerSize);
    ListIterator<VoltBulkLoaderRow> it = buf.listIterator();
    while (it.hasNext()) {
        VoltBulkLoaderRow currRow = it.next();
        VoltBulkLoader loader = currRow.m_loader;
        Object[] row_args;
        row_args = new Object[currRow.m_rowData.length];
        try {
            for (int i = 0; i < row_args.length; i++) {
                final VoltType type = m_columnTypes[i];
                row_args[i] = ParameterConverter.tryToMakeCompatible(type.classFromType(), currRow.m_rowData[i]);
            }
        } catch (VoltTypeException e) {
            loader.generateError(currRow.m_rowHandle, currRow.m_rowData, e.getMessage());
            loader.m_outstandingRowCount.decrementAndGet();
            it.remove();
            continue;
        }
        m_table.addRow(row_args);
    }
    return new PartitionProcedureCallback(buf);
}
Also used : VoltType(org.voltdb.VoltType) ArrayList(java.util.ArrayList) VoltTypeException(org.voltdb.VoltTypeException)

Example 3 with VoltTypeException

use of org.voltdb.VoltTypeException in project voltdb by VoltDB.

the class AdHocPlannedStmtBatch method flattenPlanArrayToBuffer.

/**
     * For convenience, serialization is accomplished with this single method,
     * but deserialization is piecemeal via the static methods userParamsFromBuffer
     * and planArrayFromBuffer with no dummy "AdHocPlannedStmtBatch receiver" instance required.
     */
public ByteBuffer flattenPlanArrayToBuffer() throws IOException {
    // sizeof batch
    int size = 0;
    ParameterSet userParamCache = null;
    if (userParamSet == null) {
        userParamCache = ParameterSet.emptyParameterSet();
    } else {
        Object[] typedUserParams = new Object[userParamSet.length];
        int ii = 0;
        for (AdHocPlannedStatement cs : plannedStatements) {
            for (VoltType paramType : cs.core.parameterTypes) {
                if (ii >= typedUserParams.length) {
                    String errorMsg = "Too few actual arguments were passed for the parameters in the sql statement(s): (" + typedUserParams.length + " vs. " + ii + ")";
                    // Volt-TYPE-Exception is slightly cheating, here, should there be a more general VoltArgumentException?
                    throw new VoltTypeException(errorMsg);
                }
                typedUserParams[ii] = ParameterConverter.tryToMakeCompatible(paramType.classFromType(), userParamSet[ii]);
                // System.out.println("DEBUG typed parameter: " + work.userParamSet[ii] +
                //         "using type: " + paramType + "as: " + typedUserParams[ii]);
                ii++;
            }
        }
        // exactly once in userParams.
        if (ii < typedUserParams.length) {
            // Volt-TYPE-Exception is slightly cheating, here, should there be a more general VoltArgumentException?
            String errorMsg = "Too many actual arguments were passed for the parameters in the sql statement(s): (" + typedUserParams.length + " vs. " + ii + ")";
            throw new VoltTypeException(errorMsg);
        }
        userParamCache = ParameterSet.fromArrayNoCopy(typedUserParams);
    }
    size += userParamCache.getSerializedSize();
    // sizeof batch
    size += 2;
    for (AdHocPlannedStatement cs : plannedStatements) {
        size += cs.getSerializedSize();
    }
    ByteBuffer buf = ByteBuffer.allocate(size);
    userParamCache.flattenToBuffer(buf);
    buf.putShort((short) plannedStatements.size());
    for (AdHocPlannedStatement cs : plannedStatements) {
        cs.flattenToBuffer(buf);
    }
    return buf;
}
Also used : ParameterSet(org.voltdb.ParameterSet) VoltType(org.voltdb.VoltType) JSONObject(org.json_voltpatches.JSONObject) VoltTypeException(org.voltdb.VoltTypeException) ByteBuffer(java.nio.ByteBuffer)

Example 4 with VoltTypeException

use of org.voltdb.VoltTypeException in project voltdb by VoltDB.

the class AdHocNTBase method runNonDDLAdHoc.

/**
     * Plan and execute a batch of DML/DQL sql. Any DDL has been filtered out at this point.
     */
protected CompletableFuture<ClientResponse> runNonDDLAdHoc(CatalogContext context, List<String> sqlStatements, boolean inferPartitioning, Object userPartitionKey, ExplainMode explainMode, boolean isSwapTables, Object[] userParamSet) {
    // catch races vs. updateApplicationCatalog.
    if (context == null) {
        context = VoltDB.instance().getCatalogContext();
    }
    List<String> errorMsgs = new ArrayList<>();
    List<AdHocPlannedStatement> stmts = new ArrayList<>();
    int partitionParamIndex = -1;
    VoltType partitionParamType = null;
    Object partitionParamValue = null;
    assert (sqlStatements != null);
    boolean inferSP = (sqlStatements.size() == 1) && inferPartitioning;
    if (userParamSet != null && userParamSet.length > 0) {
        if (sqlStatements.size() != 1) {
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, AdHocErrorResponseMessage);
        }
    }
    for (final String sqlStatement : sqlStatements) {
        try {
            AdHocPlannedStatement result = compileAdHocSQL(context, sqlStatement, inferSP, userPartitionKey, explainMode, isSwapTables, userParamSet);
            // and generated a partition parameter.
            if (inferSP) {
                partitionParamIndex = result.getPartitioningParameterIndex();
                partitionParamType = result.getPartitioningParameterType();
                partitionParamValue = result.getPartitioningParameterValue();
            }
            stmts.add(result);
        } catch (AdHocPlanningException e) {
            errorMsgs.add(e.getMessage());
        }
    }
    if (!errorMsgs.isEmpty()) {
        String errorSummary = StringUtils.join(errorMsgs, "\n");
        return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, errorSummary);
    }
    AdHocPlannedStmtBatch plannedStmtBatch = new AdHocPlannedStmtBatch(userParamSet, stmts, partitionParamIndex, partitionParamType, partitionParamValue, userPartitionKey == null ? null : new Object[] { userPartitionKey });
    if (adhocLog.isDebugEnabled()) {
        logBatch(context, plannedStmtBatch, userParamSet);
    }
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.CI);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.endAsync("planadhoc", getClientHandle()));
    }
    if (explainMode == ExplainMode.EXPLAIN_ADHOC) {
        return processExplainPlannedStmtBatch(plannedStmtBatch);
    } else if (explainMode == ExplainMode.EXPLAIN_DEFAULT_PROC) {
        return processExplainDefaultProc(plannedStmtBatch);
    } else {
        try {
            return createAdHocTransaction(plannedStmtBatch, isSwapTables);
        } catch (VoltTypeException vte) {
            String msg = "Unable to execute adhoc sql statement(s): " + vte.getMessage();
            return makeQuickResponse(ClientResponse.GRACEFUL_FAILURE, msg);
        }
    }
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) ArrayList(java.util.ArrayList) VoltTypeException(org.voltdb.VoltTypeException) AdHocPlannedStmtBatch(org.voltdb.compiler.AdHocPlannedStmtBatch) AdHocPlannedStatement(org.voltdb.compiler.AdHocPlannedStatement) VoltType(org.voltdb.VoltType)

Example 5 with VoltTypeException

use of org.voltdb.VoltTypeException in project voltdb by VoltDB.

the class SavedTableConverter method convertTable.

public static VoltTable convertTable(VoltTable inputTable, Table outputTableSchema, boolean shouldPreserveDRHiddenColumn) throws VoltTypeException {
    VoltTable new_table;
    if (shouldPreserveDRHiddenColumn) {
        // if the DR hidden column should be preserved in conversion, append it to the end of target schema
        new_table = CatalogUtil.getVoltTable(outputTableSchema, CatalogUtil.DR_HIDDEN_COLUMN_INFO);
    } else {
        new_table = CatalogUtil.getVoltTable(outputTableSchema);
    }
    Map<Integer, Integer> column_copy_index_map = computeColumnCopyIndexMap(inputTable, new_table);
    // if original table does not have hidden column present, we need to add
    boolean addDRHiddenColumn = shouldPreserveDRHiddenColumn && !column_copy_index_map.containsKey(new_table.getColumnCount() - 1);
    Column catalogColumnForHiddenColumn = null;
    if (addDRHiddenColumn) {
        catalogColumnForHiddenColumn = new Column();
        catalogColumnForHiddenColumn.setName(CatalogUtil.DR_HIDDEN_COLUMN_NAME);
        catalogColumnForHiddenColumn.setType(VoltType.BIGINT.getValue());
        catalogColumnForHiddenColumn.setSize(VoltType.BIGINT.getLengthInBytesForFixedTypes());
        catalogColumnForHiddenColumn.setInbytes(false);
        // small hack here to let logic below fill VoltType.NULL_BIGINT in for the hidden column
        // actually this column is not nullable in EE, but it will be set to correct value before
        // insert(restore) to the corresponding table
        catalogColumnForHiddenColumn.setNullable(true);
    }
    // Copy all the old tuples into the new table
    while (inputTable.advanceRow()) {
        Object[] coerced_values = new Object[new_table.getColumnCount()];
        for (int i = 0; i < new_table.getColumnCount(); i++) {
            if (column_copy_index_map.containsKey(i)) {
                int orig_column_index = column_copy_index_map.get(i);
                // For column we have in new table convert and make compatible value.
                coerced_values[i] = ParameterConverter.tryToMakeCompatible(new_table.getColumnType(i).classFromType(), inputTable.get(orig_column_index, inputTable.getColumnType(orig_column_index)));
            } else {
                // otherwise if it's nullable, insert null,
                Column catalog_column = outputTableSchema.getColumns().get(new_table.getColumnName(i));
                // construct an artificial catalog column for dr hidden column
                if (shouldPreserveDRHiddenColumn && catalog_column == null) {
                    catalog_column = catalogColumnForHiddenColumn;
                }
                VoltType default_type = VoltType.get((byte) catalog_column.getDefaulttype());
                if (default_type != VoltType.INVALID) {
                    // insert the default value
                    try {
                        coerced_values[i] = VoltTypeUtil.getObjectFromString(default_type, catalog_column.getDefaultvalue());
                    } catch (ParseException e) {
                        String message = "Column: ";
                        message += new_table.getColumnName(i);
                        message += " has an unparseable default: ";
                        message += catalog_column.getDefaultvalue();
                        message += " for VoltType: ";
                        message += default_type.toString();
                        throw new VoltTypeException(message);
                    }
                } else if (catalog_column.getNullable()) {
                    coerced_values[i] = null;
                } else {
                    throw new VoltTypeException("Column: " + new_table.getColumnName(i) + " has no default " + "and null is not permitted");
                }
            }
        }
        new_table.addRow(coerced_values);
    }
    return new_table;
}
Also used : Column(org.voltdb.catalog.Column) VoltType(org.voltdb.VoltType) ParseException(java.text.ParseException) VoltTypeException(org.voltdb.VoltTypeException) VoltTable(org.voltdb.VoltTable)

Aggregations

VoltType (org.voltdb.VoltType)7 VoltTypeException (org.voltdb.VoltTypeException)7 VoltTable (org.voltdb.VoltTable)3 ArrayList (java.util.ArrayList)2 ProcParameter (org.voltdb.catalog.ProcParameter)2 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)2 ImmutableMap (com.google_voltpatches.common.collect.ImmutableMap)1 Method (java.lang.reflect.Method)1 ByteBuffer (java.nio.ByteBuffer)1 ParseException (java.text.ParseException)1 JSONObject (org.json_voltpatches.JSONObject)1 ParameterSet (org.voltdb.ParameterSet)1 ProcInfo (org.voltdb.ProcInfo)1 ProcInfoData (org.voltdb.ProcInfoData)1 SQLStmt (org.voltdb.SQLStmt)1 VoltNonTransactionalProcedure (org.voltdb.VoltNonTransactionalProcedure)1 VoltProcedure (org.voltdb.VoltProcedure)1 Column (org.voltdb.catalog.Column)1 Group (org.voltdb.catalog.Group)1 GroupRef (org.voltdb.catalog.GroupRef)1