Search in sources :

Example 16 with VoltType

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

the class MaterializedViewProcessor method setTypeAttributesForColumn.

private static void setTypeAttributesForColumn(Column column, AbstractExpression expr) {
    VoltType voltTy = expr.getValueType();
    column.setType(voltTy.getValue());
    if (expr.getValueType().isVariableLength()) {
        int viewColumnLength = expr.getValueSize();
        int lengthInBytes = expr.getValueSize();
        lengthInBytes = expr.getInBytes() ? lengthInBytes : lengthInBytes * 4;
        // We don't create a view column that is wider than the default.
        if (lengthInBytes < voltTy.defaultLengthForVariableLengthType()) {
            column.setSize(viewColumnLength);
            column.setInbytes(expr.getInBytes());
        } else {
            // Declining to create a view column that is wider than the default.
            // This ensures that if there are a large number of aggregates on a string
            // column that we have a reasonable chance of not exceeding the static max row size limit.
            column.setSize(voltTy.defaultLengthForVariableLengthType());
            column.setInbytes(true);
        }
    } else {
        column.setSize(voltTy.getMaxLengthInBytes());
    }
}
Also used : VoltType(org.voltdb.VoltType) Constraint(org.voltdb.catalog.Constraint)

Example 17 with VoltType

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

the class JDBC4ResultSet method getDouble.

// Retrieves the value of the designated column in the current row of this
// ResultSet object as a double in the Java programming language.
@Override
public double getDouble(int columnIndex) throws SQLException {
    checkColumnBounds(columnIndex);
    try {
        final VoltType type = table.getColumnType(columnIndex - 1);
        Double doubleValue = null;
        switch(type) {
            case TINYINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case SMALLINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case INTEGER:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case BIGINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case FLOAT:
                doubleValue = new Double(table.getDouble(columnIndex - 1));
                break;
            case DECIMAL:
                doubleValue = table.getDecimalAsBigDecimal(columnIndex - 1).doubleValue();
                break;
            default:
                throw new IllegalArgumentException("Cannot get double value for column type '" + type + "'");
        }
        return table.wasNull() ? new Double(0) : doubleValue;
    } catch (Exception x) {
        throw SQLError.get(x);
    }
}
Also used : VoltType(org.voltdb.VoltType) SQLException(java.sql.SQLException)

Example 18 with VoltType

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

the class JDBC4ResultSet method getFloat.

// Retrieves the value of the designated column in the current row of this
// ResultSet object as a float in the Java programming language.
@Override
public float getFloat(int columnIndex) throws SQLException {
    checkColumnBounds(columnIndex);
    try {
        final VoltType type = table.getColumnType(columnIndex - 1);
        Double doubleValue = null;
        switch(type) {
            case TINYINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case SMALLINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case INTEGER:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case BIGINT:
                doubleValue = new Double(table.getLong(columnIndex - 1));
                break;
            case FLOAT:
                doubleValue = new Double(table.getDouble(columnIndex - 1));
                break;
            case DECIMAL:
                doubleValue = table.getDecimalAsBigDecimal(columnIndex - 1).doubleValue();
                break;
            default:
                throw new IllegalArgumentException("Cannot get float value for column type '" + type + "'");
        }
        if (table.wasNull()) {
            doubleValue = new Double(0);
        } else if (Math.abs(doubleValue) > new Double(Float.MAX_VALUE)) {
            throw new SQLException("Value out of float range");
        }
        return doubleValue.floatValue();
    } catch (Exception x) {
        throw SQLError.get(x);
    }
}
Also used : VoltType(org.voltdb.VoltType) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException)

Example 19 with VoltType

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

the class IndexCountPlanNode method createOrNull.

// Create an IndexCountPlanNode that replaces the parent aggregate and child
// indexscan IF the indexscan's end expressions are a form that can be
// modeled with an end key.
// The supported forms for end expression are:
//   - null
//   - one filter expression per index key component (ANDed together)
//     as "combined" for the IndexScan.
//   - fewer filter expressions than index key components with one of the
//     (the last) being a LT comparison.
//   - 1 fewer filter expressions than index key components,
//     but all ANDed equality filters
// The LT restriction comes because when index key prefixes are identical
// to the prefix-only end key, the entire index key sorts greater than the
// prefix-only end-key, because it is always longer.
// These prefix-equal cases would be missed in an EQ or LTE filter,
// causing undercounts.
// A prefix-only LT filter discards prefix-equal cases, so it is allowed.
// @return the IndexCountPlanNode or null if one is not possible.
public static IndexCountPlanNode createOrNull(IndexScanPlanNode isp, AggregatePlanNode apn) {
    // add support for reverse scan
    // for ASC scan, check endExpression;
    // for DESC scan (isReverseScan()), check the searchkeys
    List<AbstractExpression> endKeys = new ArrayList<>();
    // Translate the index scan's end condition into a list of end key
    // expressions and note the comparison operand of the last one.
    // Initially assume it to be an equality filter.
    IndexLookupType endType = IndexLookupType.EQ;
    List<AbstractExpression> endComparisons = ExpressionUtil.uncombinePredicate(isp.getEndExpression());
    for (AbstractExpression ae : endComparisons) {
        // LT or LTE expression that resets the end type.
        assert (endType == IndexLookupType.EQ);
        ExpressionType exprType = ae.getExpressionType();
        if (exprType == ExpressionType.COMPARE_LESSTHAN) {
            endType = IndexLookupType.LT;
        } else if (exprType == ExpressionType.COMPARE_LESSTHANOREQUALTO) {
            endType = IndexLookupType.LTE;
        } else {
            assert (exprType == ExpressionType.COMPARE_EQUAL || exprType == ExpressionType.COMPARE_NOTDISTINCT);
        }
        // PlanNodes all need private deep copies of expressions
        // so that the resolveColumnIndexes results
        // don't get bashed by other nodes or subsequent planner runs
        endKeys.add(ae.getRight().clone());
    }
    int indexSize = 0;
    String jsonstring = isp.getCatalogIndex().getExpressionsjson();
    List<ColumnRef> indexedColRefs = null;
    List<AbstractExpression> indexedExprs = null;
    if (jsonstring.isEmpty()) {
        indexedColRefs = CatalogUtil.getSortedCatalogItems(isp.getCatalogIndex().getColumns(), "index");
        indexSize = indexedColRefs.size();
    } else {
        try {
            indexedExprs = AbstractExpression.fromJSONArrayString(jsonstring, isp.getTableScan());
            indexSize = indexedExprs.size();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    int searchKeySize = isp.getSearchKeyExpressions().size();
    int endKeySize = endKeys.size();
    if (!isp.isReverseScan() && endType != IndexLookupType.LT && endKeySize > 0 && endKeySize < indexSize) {
        // That is, when a prefix-only key exists and does not use LT.
        if (endType != IndexLookupType.EQ || searchKeySize != indexSize || endKeySize < indexSize - 1) {
            return null;
        }
        // To use an index count for an equality search of da compound key,
        // both the search key and end key must have a component for each
        // index component.
        // If the search key is long enough but the end key is one component
        // short, it can be patched with a type-appropriate max key value
        // (if one exists for the type), but the end key comparison needs to
        // change from EQ to LTE to compensate.
        VoltType missingEndKeyType;
        // and get the missing key component's indexed expression.
        if (jsonstring.isEmpty()) {
            int lastIndex = indexedColRefs.get(endKeySize).getColumn().getIndex();
            for (AbstractExpression expr : endComparisons) {
                if (((TupleValueExpression) (expr.getLeft())).getColumnIndex() == lastIndex) {
                    return null;
                }
            }
            int catalogTypeCode = indexedColRefs.get(endKeySize).getColumn().getType();
            missingEndKeyType = VoltType.get((byte) catalogTypeCode);
        } else {
            AbstractExpression lastIndexedExpr = indexedExprs.get(endKeySize);
            for (AbstractExpression expr : endComparisons) {
                if (expr.getLeft().bindingToIndexedExpression(lastIndexedExpr) != null) {
                    return null;
                }
            }
            missingEndKeyType = lastIndexedExpr.getValueType();
        }
        String maxValueForType = missingEndKeyType.getMaxValueForKeyPadding();
        // for which all legal values are less than or equal to it.
        if (maxValueForType == null) {
            return null;
        }
        ConstantValueExpression maxKey = new ConstantValueExpression();
        maxKey.setValueType(missingEndKeyType);
        maxKey.setValue(maxValueForType);
        maxKey.setValueSize(missingEndKeyType.getLengthInBytesForFixedTypes());
        endType = IndexLookupType.LTE;
        endKeys.add(maxKey);
    }
    // DESC case
    if (searchKeySize > 0 && searchKeySize < indexSize) {
        return null;
    }
    return new IndexCountPlanNode(isp, apn, endType, endKeys);
}
Also used : IndexLookupType(org.voltdb.types.IndexLookupType) ArrayList(java.util.ArrayList) JSONException(org.json_voltpatches.JSONException) AbstractExpression(org.voltdb.expressions.AbstractExpression) VoltType(org.voltdb.VoltType) ConstantValueExpression(org.voltdb.expressions.ConstantValueExpression) ColumnRef(org.voltdb.catalog.ColumnRef) ExpressionType(org.voltdb.types.ExpressionType)

Example 20 with VoltType

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

the class ExportClientTestBase method constructTestSource.

static AdvertisedDataSource constructTestSource(boolean replicated, int partition, String tableName) {
    ArrayList<String> col_names = new ArrayList<String>();
    ArrayList<VoltType> col_types = new ArrayList<VoltType>();
    for (int i = 0; i < COLUMN_TYPES.length; i++) {
        col_names.add(COLUMN_NAMES[i]);
        col_types.add(COLUMN_TYPES[i]);
    }
    String partCol = replicated ? null : "smallint";
    //clear the table
    vtable.clearRowData();
    AdvertisedDataSource source = new AdvertisedDataSource(partition, "foo", tableName, partCol, 0, 32, col_names, col_types, Arrays.asList(COLUMN_LENGTHS), AdvertisedDataSource.ExportFormat.FOURDOTFOUR);
    return source;
}
Also used : AdvertisedDataSource(org.voltdb.export.AdvertisedDataSource) VoltType(org.voltdb.VoltType) ArrayList(java.util.ArrayList)

Aggregations

VoltType (org.voltdb.VoltType)54 AbstractExpression (org.voltdb.expressions.AbstractExpression)10 Constraint (org.voltdb.catalog.Constraint)9 BigDecimal (java.math.BigDecimal)8 ArrayList (java.util.ArrayList)8 Column (org.voltdb.catalog.Column)8 VoltXMLElement (org.hsqldb_voltpatches.VoltXMLElement)7 VoltTypeException (org.voltdb.VoltTypeException)7 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)6 JSONException (org.json_voltpatches.JSONException)5 ExpressionType (org.voltdb.types.ExpressionType)5 VoltTable (org.voltdb.VoltTable)4 Index (org.voltdb.catalog.Index)4 SQLException (java.sql.SQLException)3 ColumnRef (org.voltdb.catalog.ColumnRef)3 Table (org.voltdb.catalog.Table)3 ConstantValueExpression (org.voltdb.expressions.ConstantValueExpression)3 ParameterValueExpression (org.voltdb.expressions.ParameterValueExpression)3 TupleValueExpression (org.voltdb.expressions.TupleValueExpression)3 GeographyPointValue (org.voltdb.types.GeographyPointValue)3