use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class FunctionSQL method voltAnnotateFunctionXML.
/**
* VoltDB added method to get a non-catalog-dependent
* representation of this HSQLDB object.
* @param session The current Session object may be needed to resolve
* some names.
* @return XML, correctly indented, representing this object.
* @throws HSQLParseException
*/
VoltXMLElement voltAnnotateFunctionXML(VoltXMLElement exp) {
// XXX Should this throw HSQLParseException instead?
assert (getType() == OpTypes.SQL_FUNCTION);
exp.attributes.put("name", name);
exp.attributes.put("valuetype", dataType.getNameString());
if (parameterArg != -1) {
exp.attributes.put("result_type_parameter_index", String.valueOf(parameterArg));
}
int volt_funcType = funcType;
String implied_argument = null;
int keywordConstant = 0;
switch(funcType) {
case FUNC_SUBSTRING_CHAR:
// A little tweaking is needed here because VoltDB wants to define separate functions for 2-argument and 3-argument SUBSTRING
if (nodes.length == 2 || nodes[2] == null) {
volt_funcType = FUNC_VOLT_SUBSTRING_CHAR_FROM;
}
exp.attributes.put("function_id", String.valueOf(volt_funcType));
return exp;
case FUNC_TRIM_CHAR:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
switch(keywordConstant) {
case Tokens.BOTH:
implied_argument = "BOTH";
break;
case Tokens.LEADING:
implied_argument = "LEADING";
break;
case Tokens.TRAILING:
implied_argument = "TRAILING";
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "FunctionSQL");
}
assert (implied_argument != null);
exp.attributes.put("function_id", String.valueOf(keywordConstant + SQL_TRIM_VOLT_FUNC_OFFSET));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
case FUNC_EXTRACT:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
switch(keywordConstant) {
case Tokens.DAY_NAME:
// case DTIType.DAY_NAME :
implied_argument = "DAY_NAME";
break;
case Tokens.MONTH_NAME:
// case DTIType.MONTH_NAME :
implied_argument = "MONTH_NAME";
break;
case Tokens.QUARTER:
// case DTIType.QUARTER :
implied_argument = "QUARTER";
break;
case Tokens.DAY_OF_YEAR:
// case DTIType.DAY_OF_YEAR :
implied_argument = "DAY_OF_YEAR";
break;
case Tokens.WEEKDAY:
implied_argument = "WEEKDAY";
break;
case Tokens.DAY_OF_WEEK:
// case DTIType.DAY_OF_WEEK :
implied_argument = "DAY_OF_WEEK";
break;
case Tokens.WEEK:
keywordConstant = Tokens.WEEK_OF_YEAR;
case Tokens.WEEK_OF_YEAR:
// case DTIType.WEEK_OF_YEAR :
implied_argument = "WEEK_OF_YEAR";
break;
case Types.SQL_INTERVAL_YEAR:
implied_argument = "INTERVAL_YEAR";
break;
case Types.SQL_INTERVAL_MONTH:
implied_argument = "SQL_INTERVAL_MONTH";
break;
case Types.SQL_INTERVAL_DAY:
implied_argument = "SQL_INTERVAL_DAY";
break;
case Types.SQL_INTERVAL_HOUR:
implied_argument = "SQL_INTERVAL_HOUR";
break;
case Types.SQL_INTERVAL_MINUTE:
implied_argument = "SQL_INTERVAL_MINUTE";
break;
case Types.SQL_INTERVAL_SECOND:
implied_argument = "SQL_INTERVAL_SECOND";
break;
case Tokens.YEAR:
implied_argument = "YEAR";
break;
case Tokens.MONTH:
implied_argument = "MONTH";
break;
case Tokens.DAY_OF_MONTH:
// case DTIType.DAY_OF_MONTH :
keywordConstant = Tokens.DAY;
case Tokens.DAY:
implied_argument = "DAY";
break;
case Tokens.HOUR:
implied_argument = "HOUR";
break;
case Tokens.MINUTE:
implied_argument = "MINUTE";
break;
case Tokens.SECOND:
implied_argument = "SECOND";
break;
case Tokens.SECONDS_MIDNIGHT:
// case DTIType.SECONDS_MIDNIGHT :
implied_argument = "SECONDS_MIDNIGHT";
break;
case Tokens.TIMEZONE_HOUR:
// case DTIType.TIMEZONE_HOUR :
implied_argument = "TIMEZONE_HOUR";
break;
case Tokens.TIMEZONE_MINUTE:
// case DTIType.TIMEZONE_MINUTE :
implied_argument = "TIMEZONE_MINUTE";
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "DateTimeTypeForVoltDB: " + String.valueOf(keywordConstant));
}
assert (implied_argument != null);
exp.attributes.put("function_id", String.valueOf(keywordConstant + SQL_EXTRACT_VOLT_FUNC_OFFSET));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_SINCE_EPOCH:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
int since_epoch_func = -1;
switch(keywordConstant) {
case Tokens.SECOND:
implied_argument = "SECOND";
since_epoch_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_SINCE_EPOCH_SECOND;
break;
case Tokens.MILLIS:
case Tokens.MILLISECOND:
implied_argument = "MILLISECOND";
since_epoch_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_SINCE_EPOCH_MILLISECOND;
break;
case Tokens.MICROS:
case Tokens.MICROSECOND:
implied_argument = "MICROSECOND";
since_epoch_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_SINCE_EPOCH_MICROSECOND;
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "DateTimeTypeForVoltDB: " + String.valueOf(keywordConstant));
}
assert (implied_argument != null);
assert (-1 != since_epoch_func);
exp.attributes.put("function_id", String.valueOf(since_epoch_func));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_TO_TIMESTAMP:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
int to_timestamp_func = -1;
switch(keywordConstant) {
case Tokens.SECOND:
implied_argument = "SECOND";
to_timestamp_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TO_TIMESTAMP_SECOND;
break;
case Tokens.MILLIS:
case Tokens.MILLISECOND:
implied_argument = "MILLISECOND";
to_timestamp_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TO_TIMESTAMP_MILLISECOND;
break;
case Tokens.MICROS:
case Tokens.MICROSECOND:
implied_argument = "MICROSECOND";
to_timestamp_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TO_TIMESTAMP_MICROSECOND;
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "DateTimeTypeForVoltDB: " + String.valueOf(keywordConstant));
}
assert (-1 != to_timestamp_func);
exp.attributes.put("function_id", String.valueOf(to_timestamp_func));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_TIMESTAMP:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
int truncate_func = -1;
switch(keywordConstant) {
case Tokens.YEAR:
implied_argument = "YEAR";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_YEAR;
break;
case Tokens.QUARTER:
implied_argument = "QUARTER";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_QUARTER;
break;
case Tokens.MONTH:
implied_argument = "MONTH";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_MONTH;
break;
case Tokens.DAY:
implied_argument = "DAY";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_DAY;
break;
case Tokens.HOUR:
implied_argument = "HOUR";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_HOUR;
break;
case Tokens.MINUTE:
implied_argument = "MINUTE";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_MINUTE;
break;
case Tokens.SECOND:
implied_argument = "SECOND";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_SECOND;
break;
case Tokens.MILLIS:
case Tokens.MILLISECOND:
implied_argument = "MILLISECOND";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_MILLISECOND;
break;
case Tokens.MICROS:
case Tokens.MICROSECOND:
implied_argument = "MICROSECOND";
truncate_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_TRUNCATE_MICROSECOND;
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "DateTimeTypeForVoltDB: " + String.valueOf(keywordConstant));
}
assert (implied_argument != null);
assert (-1 != truncate_func);
exp.attributes.put("function_id", String.valueOf(truncate_func));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_DISTANCE:
Type leftChildType = nodes[0].dataType;
Type rightChildType = nodes[1].dataType;
// and point-to-point.
assert (leftChildType.isGeographyType() || leftChildType.isGeographyPointType());
assert (rightChildType.isGeographyPointType());
if (leftChildType.isGeographyType()) {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_DISTANCE_POLYGON_POINT));
} else {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_DISTANCE_POINT_POINT));
}
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_DWITHIN:
Type firstArgType = nodes[0].dataType;
Type secondArgType = nodes[1].dataType;
Type thirdArgType = nodes[2].dataType;
// resolveTypes() has logic to perform the type-validity for arguments
assert (firstArgType.isGeographyType() || firstArgType.isGeographyPointType());
assert (secondArgType.isGeographyPointType());
assert (thirdArgType.isNumberType());
if (firstArgType.isGeographyType()) {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_DWITHIN_POLYGON_POINT));
} else {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_DWITHIN_POINT_POINT));
}
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_ASTEXT:
// as unsupported types
assert (nodes[0].dataType.isGeographyPointType() || nodes[0].dataType.isGeographyType());
if (nodes[0].dataType.isGeographyPointType()) {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_ASTEXT_GEOGRAPHY_POINT));
} else {
exp.attributes.put("function_id", String.valueOf(FunctionForVoltDB.FunctionId.FUNC_VOLT_ASTEXT_GEOGRAPHY));
}
return exp;
case FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD:
implied_argument = null;
keywordConstant = ((Integer) nodes[0].valueData).intValue();
int dateadd_func = -1;
switch(keywordConstant) {
case Tokens.YEAR:
implied_argument = "YEAR";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_YEAR;
break;
case Tokens.QUARTER:
implied_argument = "QUARTER";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_QUARTER;
break;
case Tokens.MONTH:
implied_argument = "MONTH";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_MONTH;
break;
case Tokens.DAY:
implied_argument = "DAY";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_DAY;
break;
case Tokens.HOUR:
implied_argument = "HOUR";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_HOUR;
break;
case Tokens.MINUTE:
implied_argument = "MINUTE";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_MINUTE;
break;
case Tokens.SECOND:
implied_argument = "SECOND";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_SECOND;
break;
case Tokens.MILLIS:
case Tokens.MILLISECOND:
implied_argument = "MILLISECOND";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_MILLISECOND;
break;
case Tokens.MICROS:
case Tokens.MICROSECOND:
implied_argument = "MICROSECOND";
dateadd_func = FunctionForVoltDB.FunctionId.FUNC_VOLT_DATEADD_MICROSECOND;
break;
default:
throw Error.runtimeError(ErrorCode.U_S0500, "DateTimeTypeForVoltDB: " + String.valueOf(keywordConstant));
}
assert (implied_argument != null);
assert (-1 != dateadd_func);
exp.attributes.put("function_id", String.valueOf(dateadd_func));
exp.attributes.put("implied_argument", implied_argument);
// Having accounted for the first argument, remove it from the child expression list.
exp.children.remove(0);
return exp;
default:
if (voltDisabled != null) {
exp.attributes.put("disabled", voltDisabled);
}
exp.attributes.put("function_id", String.valueOf(volt_funcType));
return exp;
}
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class Expression method prepareTable.
void prepareTable(Session session, Expression row, int degree) {
if (nodeDataTypes != null) {
return;
}
for (int i = 0; i < nodes.length; i++) {
Expression e = nodes[i];
if (e.opType == OpTypes.ROW) {
if (degree != e.nodes.length) {
throw Error.error(ErrorCode.X_42564);
}
} else if (degree == 1) {
nodes[i] = new Expression(OpTypes.ROW);
nodes[i].nodes = new Expression[] { e };
} else {
throw Error.error(ErrorCode.X_42564);
}
}
nodeDataTypes = new Type[degree];
for (int j = 0; j < degree; j++) {
Type type = row == null ? null : row.nodes[j].dataType;
for (int i = 0; i < nodes.length; i++) {
type = Type.getAggregateType(nodes[i].nodes[j].dataType, type);
}
if (type == null) {
throw Error.error(ErrorCode.X_42567);
}
nodeDataTypes[j] = type;
if (row != null && row.nodes[j].isParam) {
row.nodes[j].dataType = type;
}
for (int i = 0; i < nodes.length; i++) {
if (nodes[i].nodes[j].isParam) {
nodes[i].nodes[j].dataType = nodeDataTypes[j];
continue;
}
if (nodes[i].nodes[j].opType == OpTypes.VALUE) {
if (nodes[i].nodes[j].valueData == null) {
nodes[i].nodes[j].dataType = nodeDataTypes[j];
}
}
}
if (nodeDataTypes[j].isCharacterType() && !((CharacterType) nodeDataTypes[j]).isEqualIdentical()) {
// collation issues
}
}
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class ExpressionLogical method resolveTypesForAllAny.
void resolveTypesForAllAny(Session session) {
int degree = nodes[LEFT].getDegree();
if (degree == 1 && nodes[LEFT].opType != OpTypes.ROW) {
nodes[LEFT] = new Expression(OpTypes.ROW, new Expression[] { nodes[LEFT] });
}
if (nodes[RIGHT].opType == OpTypes.TABLE) {
nodes[RIGHT].prepareTable(session, nodes[LEFT], degree);
nodes[RIGHT].subQuery.prepareTable(session);
if (nodes[RIGHT].isCorrelated) {
nodes[RIGHT].subQuery.setCorrelated();
}
}
if (degree != nodes[RIGHT].nodeDataTypes.length) {
throw Error.error(ErrorCode.X_42564);
}
if (nodes[RIGHT].opType == OpTypes.TABLE) {
}
nodes[LEFT].nodeDataTypes = new Type[nodes[LEFT].nodes.length];
for (int i = 0; i < nodes[LEFT].nodeDataTypes.length; i++) {
Type type = nodes[LEFT].nodes[i].dataType;
if (type == null) {
type = nodes[RIGHT].nodeDataTypes[i];
} else // A VoltDB extension to support "IN ?"
if (i == 0 && degree == 1 && nodes[RIGHT].opType == OpTypes.DYNAMIC_PARAM && nodes[RIGHT].nodeDataTypes != null && nodes[RIGHT].nodeDataTypes.length == 1 && nodes[RIGHT].nodeDataTypes[0] == null) {
if (type.isIntegralType()) {
// promote parameter type to vector of BIGINT regardless of exact LHS integer scale.
nodes[RIGHT].nodeDataTypes[0] = Type.SQL_BIGINT;
} else {
nodes[RIGHT].nodeDataTypes[0] = type;
}
}
if (type == null) {
throw Error.error(ErrorCode.X_42567);
}
nodes[LEFT].nodeDataTypes[i] = type;
}
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class Scanner method convertToNumber.
/*
* synchronized methods for use with shared Scanner objects used for type
* conversion
*/
public synchronized Number convertToNumber(String s, NumberType numberType) {
Number number;
boolean minus = false;
Type type;
reset(s);
resetState();
scanWhitespace();
scanToken();
scanWhitespace();
if (token.tokenType == Tokens.PLUS) {
scanToken();
scanWhitespace();
} else if (token.tokenType == Tokens.MINUS) {
minus = true;
scanToken();
scanWhitespace();
}
if (!hasNonSpaceSeparator && token.tokenType == Tokens.X_VALUE && token.tokenValue instanceof Number) {
number = (Number) token.tokenValue;
type = token.dataType;
if (minus) {
number = (Number) token.dataType.negate(number);
}
scanEnd();
if (token.tokenType == Tokens.X_ENDPARSE) {
number = (Number) numberType.convertToType(null, number, type);
return number;
}
}
throw Error.error(ErrorCode.X_22018);
}
use of org.hsqldb_voltpatches.types.Type in project voltdb by VoltDB.
the class SchemaManager method removeSchemaObject.
void removeSchemaObject(HsqlName name) {
Schema schema = (Schema) schemaMap.get(name.schema.name);
SchemaObject object = null;
SchemaObjectSet set = null;
switch(name.type) {
case SchemaObject.SEQUENCE:
set = schema.sequenceLookup;
object = set.getObject(name.name);
break;
case SchemaObject.TABLE:
case SchemaObject.VIEW:
{
set = schema.tableLookup;
object = set.getObject(name.name);
set.remove(name.name);
break;
}
case SchemaObject.CHARSET:
set = schema.charsetLookup;
object = set.getObject(name.name);
break;
case SchemaObject.COLLATION:
set = schema.collationLookup;
object = set.getObject(name.name);
break;
case SchemaObject.PROCEDURE:
set = schema.procedureLookup;
object = set.getObject(name.name);
break;
case SchemaObject.FUNCTION:
set = schema.functionLookup;
object = set.getObject(name.name);
break;
case SchemaObject.DOMAIN:
case SchemaObject.TYPE:
set = schema.typeLookup;
object = set.getObject(name.name);
break;
case SchemaObject.INDEX:
set = schema.indexLookup;
break;
case SchemaObject.CONSTRAINT:
{
set = schema.constraintLookup;
if (name.parent.type == SchemaObject.TABLE) {
Table table = (Table) schema.tableList.get(name.parent.name);
object = table.getConstraint(name.name);
table.removeConstraint(name.name);
} else if (name.parent.type == SchemaObject.DOMAIN) {
Type type = (Type) schema.typeLookup.getObject(name.parent.name);
object = type.userTypeModifier.getConstraint(name.name);
type.userTypeModifier.removeConstraint(name.name);
}
break;
}
case SchemaObject.TRIGGER:
{
set = schema.triggerLookup;
Table table = (Table) schema.tableList.get(name.parent.name);
object = table.getTrigger(name.name);
table.removeTrigger(name.name);
break;
}
}
if (object != null) {
database.getGranteeManager().removeDbObject(object.getName());
removeReferencingObject(object);
}
set.remove(name.name);
removeReferencedObject(name);
}
Aggregations