use of org.voltdb.VoltType in project voltdb by VoltDB.
the class FunctionExpression method refineOperandType.
@Override
public void refineOperandType(VoltType columnType) {
if (m_resultTypeParameterIndex == NOT_PARAMETERIZED) {
// Further refinement should be useless/un-possible.
return;
}
// and have that change propagate up to its return type.
if (m_valueType != null && m_valueType != VoltType.NUMERIC) {
return;
}
AbstractExpression arg = m_args.get(m_resultTypeParameterIndex);
VoltType valueType = arg.getValueType();
if (valueType != null && valueType != VoltType.NUMERIC) {
return;
}
arg.refineOperandType(columnType);
m_valueType = arg.getValueType();
m_valueSize = m_valueType.getLengthInBytesForFixedTypes();
}
use of org.voltdb.VoltType in project voltdb by VoltDB.
the class FunctionExpression method refineValueType.
@Override
public void refineValueType(VoltType neededType, int neededSize) {
if (m_resultTypeParameterIndex == NOT_PARAMETERIZED) {
// Further refinement should be useless/un-possible.
return;
}
// and have that change propagate up to its return type.
if (m_valueType != null && m_valueType != VoltType.NUMERIC) {
return;
}
AbstractExpression arg = m_args.get(m_resultTypeParameterIndex);
VoltType valueType = arg.getValueType();
if (valueType != null && valueType != VoltType.NUMERIC) {
return;
}
// No assumption is made that functions that are parameterized by
// variably-sized types are size-preserving, so allow any size
arg.refineValueType(neededType, neededType.getMaxLengthInBytes());
m_valueType = arg.getValueType();
m_valueSize = m_valueType.getMaxLengthInBytes();
}
use of org.voltdb.VoltType in project voltdb by VoltDB.
the class OperatorExpression method refineOperandType.
@Override
public void refineOperandType(VoltType columnType) {
if ((m_valueType != null) && (m_valueType != VoltType.NUMERIC)) {
return;
}
ExpressionType type = getExpressionType();
if (type == ExpressionType.OPERATOR_IS_NULL || type == ExpressionType.OPERATOR_NOT) {
m_valueType = VoltType.BOOLEAN;
m_valueSize = m_valueType.getLengthInBytesForFixedTypes();
return;
}
m_left.refineOperandType(columnType);
//XXX Not sure how unary minus (and unary plus?) are handled (possibly via an implicit zero left argument?)
m_right.refineOperandType(columnType);
VoltType cast_type = VoltTypeUtil.determineImplicitCasting(m_left.getValueType(), m_right.getValueType());
if (cast_type == VoltType.INVALID) {
throw new RuntimeException("ERROR: Invalid output value type for Expression '" + this + "'");
}
m_valueType = cast_type;
m_valueSize = cast_type.getLengthInBytesForFixedTypes();
}
use of org.voltdb.VoltType in project voltdb by VoltDB.
the class DDLCompiler method handlePartitions.
void handlePartitions(Database db) throws VoltCompilerException {
// Actually parse and handle all the partitions
// this needs to happen before procedures are compiled
String msg = "In database, ";
final CatalogMap<Table> tables = db.getTables();
for (Table table : tables) {
String tableName = table.getTypeName();
if (m_tracker.m_partitionMap.containsKey(tableName.toLowerCase())) {
String colName = m_tracker.m_partitionMap.get(tableName.toLowerCase());
// because it defaults to replicated in the catalog.
if (colName != null) {
assert (tables.getIgnoreCase(tableName) != null);
if (m_matViewMap.containsKey(table)) {
msg += "the materialized view is automatically partitioned based on its source table. " + "Invalid PARTITION statement on view table " + tableName + ".";
throw m_compiler.new VoltCompilerException(msg);
}
final Column partitionCol = table.getColumns().getIgnoreCase(colName);
// make sure the column exists
if (partitionCol == null) {
msg += "PARTITION has unknown COLUMN '" + colName + "'";
throw m_compiler.new VoltCompilerException(msg);
}
// make sure the column is marked not-nullable
if (partitionCol.getNullable() == true) {
msg += "Partition column '" + tableName + "." + colName + "' is nullable. " + "Partition columns must be constrained \"NOT NULL\".";
throw m_compiler.new VoltCompilerException(msg);
}
// verify that the partition column is a supported type
VoltType pcolType = VoltType.get((byte) partitionCol.getType());
switch(pcolType) {
case TINYINT:
case SMALLINT:
case INTEGER:
case BIGINT:
case STRING:
case VARBINARY:
break;
default:
msg += "Partition column '" + tableName + "." + colName + "' is not a valid type. " + "Partition columns must be an integer, varchar or varbinary type.";
throw m_compiler.new VoltCompilerException(msg);
}
table.setPartitioncolumn(partitionCol);
table.setIsreplicated(false);
// Check valid indexes, whether they contain the partition column or not.
for (Index index : table.getIndexes()) {
checkValidPartitionTableIndex(index, partitionCol, tableName);
}
}
}
}
}
use of org.voltdb.VoltType in project voltdb by VoltDB.
the class DDLCompiler method addColumnToCatalog.
private static void addColumnToCatalog(Table table, VoltXMLElement node, SortedMap<Integer, VoltType> columnTypes, Map<String, Column> columnMap, VoltCompiler compiler) throws VoltCompilerException {
assert node.name.equals("column");
String name = node.attributes.get("name");
String typename = node.attributes.get("valuetype");
String nullable = node.attributes.get("nullable");
String sizeString = node.attributes.get("size");
int index = Integer.valueOf(node.attributes.get("index"));
String defaultvalue = null;
String defaulttype = null;
int defaultFuncID = -1;
// Default Value
for (VoltXMLElement child : node.children) {
if (child.name.equals("default")) {
for (VoltXMLElement inner_child : child.children) {
// Value
if (inner_child.name.equals("value")) {
// There should be only one default value/type.
assert (defaulttype == null);
defaultvalue = inner_child.attributes.get("value");
defaulttype = inner_child.attributes.get("valuetype");
assert (defaulttype != null);
} else if (inner_child.name.equals("function")) {
// There should be only one default value/type.
assert (defaulttype == null);
defaultFuncID = Integer.parseInt(inner_child.attributes.get("function_id"));
defaultvalue = inner_child.attributes.get("name");
defaulttype = inner_child.attributes.get("valuetype");
assert (defaulttype != null);
}
}
}
}
if (defaulttype != null) {
// fyi: Historically, VoltType class initialization errors get reported on this line (?).
defaulttype = Integer.toString(VoltType.typeFromString(defaulttype).getValue());
}
// replace newlines in default values
if (defaultvalue != null) {
defaultvalue = defaultvalue.replace('\n', ' ');
defaultvalue = defaultvalue.replace('\r', ' ');
}
// fyi: Historically, VoltType class initialization errors get reported on this line (?).
VoltType type = VoltType.typeFromString(typename);
columnTypes.put(index, type);
if (defaultFuncID == -1) {
if (defaultvalue != null && (type == VoltType.DECIMAL || type == VoltType.NUMERIC)) {
// Until we support deserializing scientific notation in the EE, we'll
// coerce default values to plain notation here. See ENG-952 for more info.
BigDecimal temp = new BigDecimal(defaultvalue);
defaultvalue = temp.toPlainString();
}
} else {
// Concat function name and function id, format: NAME:ID
// Used by PlanAssembler:getNextInsertPlan().
defaultvalue = defaultvalue + ":" + String.valueOf(defaultFuncID);
}
Column column = table.getColumns().add(name);
// need to set other column data here (default, nullable, etc)
column.setName(name);
column.setIndex(index);
column.setType(type.getValue());
column.setNullable(Boolean.valueOf(nullable));
int size = type.getMaxLengthInBytes();
boolean inBytes = false;
if (node.attributes.containsKey("bytes")) {
inBytes = Boolean.valueOf(node.attributes.get("bytes"));
}
// Determine the length of columns with a variable-length type
if (type.isVariableLength()) {
int userSpecifiedSize = 0;
if (sizeString != null) {
userSpecifiedSize = Integer.parseInt(sizeString);
}
if (userSpecifiedSize == 0) {
// So size specified in the column definition. Either:
// - the user-specified size is zero (unclear how this would happen---
// if someone types VARCHAR(0) HSQL will complain)
// - or the sizeString was null, meaning that the size specifier was
// omitted.
// Choose an appropriate default for the type.
size = type.defaultLengthForVariableLengthType();
} else {
if (userSpecifiedSize < 0 || (inBytes && userSpecifiedSize > VoltType.MAX_VALUE_LENGTH)) {
String msg = type.toSQLString() + " column " + name + " in table " + table.getTypeName() + " has unsupported length " + sizeString;
throw compiler.new VoltCompilerException(msg);
}
if (!inBytes && type == VoltType.STRING) {
if (userSpecifiedSize > VoltType.MAX_VALUE_LENGTH_IN_CHARACTERS) {
String msg = String.format("The size of VARCHAR column %s in table %s greater than %d " + "will be enforced as byte counts rather than UTF8 character counts. " + "To eliminate this warning, specify \"VARCHAR(%d BYTES)\"", name, table.getTypeName(), VoltType.MAX_VALUE_LENGTH_IN_CHARACTERS, userSpecifiedSize);
compiler.addWarn(msg);
inBytes = true;
}
}
if (userSpecifiedSize < type.getMinLengthInBytes()) {
String msg = type.toSQLString() + " column " + name + " in table " + table.getTypeName() + " has length of " + sizeString + " which is shorter than " + type.getMinLengthInBytes() + ", " + "the minimum allowed length for the type.";
throw compiler.new VoltCompilerException(msg);
}
size = userSpecifiedSize;
}
}
column.setInbytes(inBytes);
column.setSize(size);
column.setDefaultvalue(defaultvalue);
if (defaulttype != null)
column.setDefaulttype(Integer.parseInt(defaulttype));
columnMap.put(name, column);
}
Aggregations