use of org.hsqldb_voltpatches.types.NumberType in project voltdb by VoltDB.
the class FunctionSQL method resolveTypes.
@Override
public void resolveTypes(Session session, Expression parent) {
for (int i = 0; i < nodes.length; i++) {
if (nodes[i] != null) {
nodes[i].resolveTypes(session, this);
}
}
switch(funcType) {
case FUNC_POSITION_CHAR:
case FUNC_POSITION_BINARY:
{
if (nodes[0].dataType == null) {
if (nodes[1].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
if (nodes[1].dataType.typeCode == Types.SQL_CLOB || nodes[1].dataType.isBinaryType()) {
nodes[0].dataType = nodes[1].dataType;
} else {
nodes[0].dataType = Type.SQL_VARCHAR_DEFAULT;
}
}
if (nodes[1].dataType == null) {
if (nodes[0].dataType.typeCode == Types.SQL_CLOB || nodes[0].dataType.isBinaryType()) {
nodes[1].dataType = nodes[0].dataType;
} else {
nodes[1].dataType = Type.SQL_VARCHAR_DEFAULT;
}
}
if (nodes[0].dataType.isCharacterType() && nodes[1].dataType.isCharacterType()) {
funcType = FUNC_POSITION_CHAR;
} else if (nodes[0].dataType.isBinaryType() && nodes[1].dataType.isBinaryType()) {
if (nodes[0].dataType.isBitType() || nodes[1].dataType.isBitType()) {
throw Error.error(ErrorCode.X_42565);
}
funcType = FUNC_POSITION_BINARY;
} else {
throw Error.error(ErrorCode.X_42565);
}
dataType = Type.SQL_BIGINT;
break;
}
/*
case FUNC_OCCURENCES_REGEX :
case FUNC_POSITION_REGEX :
*/
case FUNC_EXTRACT:
{
if (nodes[1].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
if (!nodes[1].dataType.isDateTimeType() && !nodes[1].dataType.isIntervalType()) {
throw Error.error(ErrorCode.X_42565);
}
int part = ((Number) nodes[0].valueData).intValue();
DTIType type = (DTIType) nodes[1].dataType;
part = DTIType.getFieldNameTypeForToken(part);
dataType = type.getExtractType(part);
break;
}
case FUNC_BIT_LENGTH:
{
if (nodes[0].dataType == null) {
nodes[0].dataType = Type.SQL_BIT_VARYING_MAX_LENGTH;
}
if (!nodes[0].dataType.isCharacterType() && !nodes[0].dataType.isBinaryType()) {
throw Error.error(ErrorCode.X_42565);
}
dataType = Type.SQL_BIGINT;
break;
}
case FUNC_CHAR_LENGTH:
case FUNC_OCTET_LENGTH:
{
if (nodes[0].dataType == null) {
nodes[0].dataType = Type.SQL_VARCHAR_DEFAULT;
} else if (!nodes[0].dataType.isCharacterType() && ((funcType == FUNC_CHAR_LENGTH) || (!nodes[0].dataType.isBinaryType() && (funcType == FUNC_OCTET_LENGTH)))) {
throw Error.error(ErrorCode.X_42565);
}
dataType = Type.SQL_BIGINT;
break;
}
case FUNC_CARDINALITY:
{
dataType = Type.SQL_BIGINT;
break;
}
case FUNC_MOD:
{
if (nodes[0].dataType == null) {
if (nodes[1].dataType == null) {
// Data types for both operands are unknown, throw exception.
throw Error.error(ErrorCode.X_42567);
}
nodes[0].dataType = nodes[1].dataType;
}
if (nodes[0].dataType.isIntegralType()) {
// Promote the data type to BIGINT for integral data types.
nodes[0].dataType = Type.SQL_BIGINT;
}
if (nodes[1].dataType == null) {
nodes[1].dataType = nodes[0].dataType;
}
// "scale != 0", supported by customer request).
if (!(nodes[0].dataType.isIntegralType() || nodes[0].dataType.typeCode == Types.SQL_DECIMAL)) {
throw Error.error(ErrorCode.X_42565);
}
if (!(nodes[1].dataType.isIntegralType() || nodes[1].dataType.typeCode == Types.SQL_DECIMAL)) {
throw Error.error(ErrorCode.X_42565);
}
// (by the decision of the requesting customer).
if (nodes[0].dataType.isIntegralType() != nodes[1].dataType.isIntegralType()) {
throw Error.error(ErrorCode.X_42565);
}
parameterArg = 1;
dataType = nodes[1].dataType;
break;
}
case FUNC_POWER:
{
if (nodes[0].dataType == null) {
// A VoltDB extension to customize the SQL function set support
// VoltDB swapped out this odd propagation of nulls.
// VoltDB simply gives missing types the benefit of the doubt.
nodes[0].dataType = Type.SQL_DOUBLE;
// For VoltDB, the retest for null below is now redundant.
/* disable 1 line ...
nodes[1].dataType = nodes[0].dataType;
... disabled 1 line */
// End of VoltDB extension
}
if (nodes[1].dataType == null) {
// VoltDB swapped out this odd propagation of nulls.
// ORIGINAL HSQL CODE: nodes[0].dataType = nodes[1].dataType;
// VoltDB simply gives missing types the benefit of the doubt.
nodes[1].dataType = Type.SQL_DOUBLE;
// A VoltDB extension to customize the SQL function set support
// VoltDB swapped out this odd propagation of nulls.
/* disable 1 line ...
nodes[0].dataType = nodes[1].dataType;
... disabled 1 line */
// End of VoltDB extension
}
if (nodes[0].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
if (!nodes[0].dataType.isNumberType() || !nodes[1].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
nodes[0].dataType = Type.SQL_DOUBLE;
nodes[1].dataType = Type.SQL_DOUBLE;
dataType = Type.SQL_DOUBLE;
break;
}
case FUNC_LN:
case FUNC_EXP:
case FUNC_SQRT:
{
if (nodes[0].dataType == null) {
nodes[0].dataType = Type.SQL_DOUBLE;
}
if (!nodes[0].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
nodes[0].dataType = Type.SQL_DOUBLE;
dataType = Type.SQL_DOUBLE;
break;
}
case FUNC_ABS:
if (nodes[0].dataType != null && nodes[0].dataType.isIntervalType()) {
dataType = nodes[0].dataType;
// A VoltDB extension to customize the SQL function set support
parameterArg = 0;
break;
}
// $FALL-THROUGH$
case FUNC_FLOOR:
case FUNC_CEILING:
{
if (nodes[0].dataType == null) {
nodes[0].dataType = Type.SQL_DOUBLE;
}
if (!nodes[0].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
dataType = nodes[0].dataType;
// A VoltDB extension to customize the SQL function set support
parameterArg = 0;
break;
}
case FUNC_WIDTH_BUCKET:
{
if (nodes[0].dataType == null || nodes[1].dataType == null || nodes[2].dataType == null || nodes[3].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
if (!nodes[0].dataType.isNumberType() || !nodes[1].dataType.isNumberType() || !nodes[2].dataType.isNumberType() || !nodes[3].dataType.isIntegralType()) {
throw Error.error(ErrorCode.X_42565);
}
dataType = nodes[3].dataType;
// A VoltDB extension to customize the SQL function set support
parameterArg = 3;
break;
}
case FUNC_SUBSTRING_CHAR:
case FUNC_SUBSTRING_BINARY:
{
if (nodes[0].dataType == null) {
// in 20.6 parameter not allowed as type cannot be determined as binary or char
throw Error.error(ErrorCode.X_42567);
}
if (nodes[1].dataType == null) {
nodes[1].dataType = NumberType.SQL_NUMERIC_DEFAULT_INT;
}
if (!nodes[1].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
/* disable 1 line ...
if (nodes[2] != null) {
... disabled 1 line */
if (nodes.length > 2 && nodes[2] != null) {
// End of VoltDB extension
if (nodes[2].dataType == null) {
nodes[2].dataType = NumberType.SQL_NUMERIC_DEFAULT_INT;
}
if (!nodes[2].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
nodes[2].dataType = ((NumberType) nodes[2].dataType).getIntegralType();
}
dataType = nodes[0].dataType;
// A VoltDB extension to customize the SQL function set support
parameterArg = 0;
if (dataType.isCharacterType()) {
funcType = FUNC_SUBSTRING_CHAR;
if (dataType.typeCode == Types.SQL_CHAR) {
dataType = CharacterType.getCharacterType(Types.SQL_VARCHAR, dataType.precision);
}
} else if (dataType.isBinaryType()) {
funcType = FUNC_SUBSTRING_BINARY;
} else {
throw Error.error(ErrorCode.X_42565);
}
if (nodes.length > 3 && nodes[3] != null) {
// always boolean constant if defined
}
break;
}
/*
case FUNCTION_SUBSTRING_REG_EXPR :
break;
case FUNCTION_SUBSTRING_REGEX :
break;
*/
case FUNC_FOLD_LOWER:
case FUNC_FOLD_UPPER:
if (nodes[0].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
dataType = nodes[0].dataType;
// A VoltDB extension to customize the SQL function set support
parameterArg = 0;
if (!dataType.isCharacterType()) {
throw Error.error(ErrorCode.X_42565);
}
break;
/*
case FUNCTION_TRANSCODING :
break;
case FUNCTION_TRANSLITERATION :
break;
case FUNCTION_REGEX_TRANSLITERATION :
break;
*/
case FUNC_TRIM_CHAR:
case FUNC_TRIM_BINARY:
if (nodes[0] == null) {
nodes[0] = new ExpressionValue(ValuePool.getInt(Tokens.BOTH), Type.SQL_INTEGER);
}
// with the default value ' '.
if (nodes[2] == null) {
nodes[2] = nodes[1];
nodes[1] = null;
}
// End of VoltDB extension
if (nodes[2].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
dataType = nodes[2].dataType;
if (dataType.isCharacterType()) {
funcType = FUNC_TRIM_CHAR;
if (dataType.typeCode == Types.SQL_CHAR) {
dataType = CharacterType.getCharacterType(Types.SQL_VARCHAR, dataType.precision);
}
if (nodes[1] == null) {
nodes[1] = new ExpressionValue(" ", Type.SQL_CHAR);
} else // A VoltDB extension to customize the SQL function set support
if (nodes[1].dataType != Type.SQL_CHAR) {
nodes[1].dataType = Type.SQL_CHAR;
}
// End of VoltDB extension
} else if (dataType.isBinaryType()) {
funcType = FUNC_TRIM_BINARY;
if (nodes[1] == null) {
nodes[1] = new ExpressionValue(new BinaryData(new byte[] { 0 }, false), Type.SQL_BINARY);
}
} else {
throw Error.error(ErrorCode.X_42565);
}
break;
case FUNC_OVERLAY_CHAR:
case FUNC_OVERLAY_BINARY:
{
if (nodes[0].dataType == null) {
if (nodes[1].dataType == null) {
throw Error.error(ErrorCode.X_42567);
}
if (nodes[1].dataType.typeCode == Types.SQL_CLOB || nodes[1].dataType.isBinaryType()) {
nodes[0].dataType = nodes[1].dataType;
} else {
nodes[0].dataType = Type.SQL_VARCHAR_DEFAULT;
}
}
if (nodes[1].dataType == null) {
if (nodes[0].dataType.typeCode == Types.SQL_CLOB || nodes[0].dataType.isBinaryType()) {
nodes[1].dataType = nodes[0].dataType;
} else {
nodes[1].dataType = Type.SQL_VARCHAR_DEFAULT;
}
}
if (nodes[0].dataType.isCharacterType() && nodes[1].dataType.isCharacterType()) {
funcType = FUNC_OVERLAY_CHAR;
if (nodes[0].dataType.typeCode == Types.SQL_CLOB || nodes[1].dataType.typeCode == Types.SQL_CLOB) {
dataType = CharacterType.getCharacterType(Types.SQL_CLOB, nodes[0].dataType.precision + nodes[1].dataType.precision);
} else {
dataType = CharacterType.getCharacterType(Types.SQL_VARCHAR, nodes[0].dataType.precision + nodes[1].dataType.precision);
}
} else if (nodes[0].dataType.isBinaryType() && nodes[1].dataType.isBinaryType()) {
funcType = FUNC_OVERLAY_BINARY;
if (nodes[0].dataType.typeCode == Types.SQL_BLOB || nodes[1].dataType.typeCode == Types.SQL_BLOB) {
dataType = BinaryType.getBinaryType(Types.SQL_BLOB, nodes[0].dataType.precision + nodes[1].dataType.precision);
} else {
dataType = BinaryType.getBinaryType(Types.SQL_VARBINARY, nodes[0].dataType.precision + nodes[1].dataType.precision);
}
} else {
throw Error.error(ErrorCode.X_42565);
}
// A VoltDB extension to customize the SQL function set support
parameterArg = 0;
if (nodes[2].dataType == null) {
nodes[2].dataType = NumberType.SQL_NUMERIC_DEFAULT_INT;
}
if (!nodes[2].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
nodes[2].dataType = ((NumberType) nodes[2].dataType).getIntegralType();
if (nodes[3] != null) {
if (nodes[3].dataType == null) {
nodes[3].dataType = NumberType.SQL_NUMERIC_DEFAULT_INT;
}
if (!nodes[3].dataType.isNumberType()) {
throw Error.error(ErrorCode.X_42565);
}
nodes[3].dataType = ((NumberType) nodes[3].dataType).getIntegralType();
}
break;
}
/*
case FUNCTION_CHAR_NORMALIZE :
break;
*/
case FUNC_CURRENT_CATALOG:
case FUNC_CURRENT_DEFAULT_TRANSFORM_GROUP:
case FUNC_CURRENT_PATH:
case FUNC_CURRENT_ROLE:
case FUNC_CURRENT_SCHEMA:
case FUNC_CURRENT_TRANSFORM_GROUP_FOR_TYPE:
case FUNC_CURRENT_USER:
case FUNC_SESSION_USER:
case FUNC_SYSTEM_USER:
case FUNC_USER:
dataType = SqlInvariants.SQL_IDENTIFIER;
break;
case FUNC_VALUE:
break;
case FUNC_CURRENT_DATE:
dataType = CharacterType.SQL_DATE;
break;
case FUNC_CURRENT_TIME:
{
int precision = DateTimeType.defaultTimeFractionPrecision;
if (nodes[0] != null) {
precision = ((Integer) nodes[0].valueData).intValue();
}
dataType = DateTimeType.getDateTimeType(Types.SQL_TIME_WITH_TIME_ZONE, precision);
break;
}
case FUNC_CURRENT_TIMESTAMP:
{
// A VoltDB extension to disable TIME ZONE support
dataType = Type.SQL_TIMESTAMP;
break;
}
case FUNC_LOCALTIME:
{
int precision = DateTimeType.defaultTimeFractionPrecision;
if (nodes.length > 0 && nodes[0] != null) {
precision = ((Integer) nodes[0].valueData).intValue();
}
dataType = DateTimeType.getDateTimeType(Types.SQL_TIME, precision);
break;
}
case FUNC_LOCALTIMESTAMP:
{
int precision = DateTimeType.defaultTimestampFractionPrecision;
if (nodes[0] != null) {
precision = ((Integer) nodes[0].valueData).intValue();
}
dataType = DateTimeType.getDateTimeType(Types.SQL_TIMESTAMP, precision);
break;
}
default:
throw Error.runtimeError(ErrorCode.U_S0500, "FunctionSQL");
}
}
use of org.hsqldb_voltpatches.types.NumberType in project voltdb by VoltDB.
the class Expression method voltGetXML.
/**
* VoltDB added method to get a non-catalog-dependent
* representation of this HSQLDB object.
* @param context The context encapsulates the current Session object and (optionally)
* select statement display columns that may be needed to resolve some names.
* @return A VoltXML tree structure.
* @throws HSQLParseException
*/
VoltXMLElement voltGetXML(SimpleColumnContext context, String realAlias) throws HSQLParseException {
// The voltXML representations of expressions tends to be driven much more by the expression's opType
// than its Expression class.
int exprOp = getType();
// That case gets explicitly enabled here by fudging the opType from SIMPLE_COLUMN to COLUMN.
if (exprOp == OpTypes.SIMPLE_COLUMN) {
VoltXMLElement asResolved = context.resolveSimpleColumn(this);
if (asResolved != null) {
return asResolved;
}
// ENG-10429 moved the following two lines here. See fix note https://issues.voltdb.com/browse/ENG-10429.
// convert the SIMPLE_COLUMN into a COLUMN
opType = OpTypes.COLUMN;
exprOp = OpTypes.COLUMN;
}
// Use the opType to find a pre-initialized prototype VoltXMLElement with the correct
// name and any required hard-coded values pre-set.
VoltXMLElement exp = prototypes.get(exprOp);
if (exp == null) {
// Must have found an unsupported opType.
throwForUnsupportedExpression(exprOp);
}
// Duplicate the prototype and add any expression particulars needed for the specific opType value,
// as well as a unique identifier, a possible alias, and child nodes.
exp = exp.duplicate();
exp.attributes.put("id", getUniqueId(context.m_session));
if (realAlias != null) {
exp.attributes.put("alias", realAlias);
} else if ((alias != null) && (getAlias().length() > 0)) {
exp.attributes.put("alias", getAlias());
}
// Add expression sub type
if (exprSubType == OpTypes.ANY_QUANTIFIED) {
exp.attributes.put("opsubtype", "any");
} else if (exprSubType == OpTypes.ALL_QUANTIFIED) {
exp.attributes.put("opsubtype", "all");
}
for (Expression expr : nodes) {
if (expr != null) {
VoltXMLElement vxmle = expr.voltGetXML(context, null);
exp.children.add(vxmle);
assert (vxmle != null);
}
}
// VoltXMLElement.
switch(exprOp) {
case OpTypes.VALUE:
// (I'm not sure why this MUST be the case --paul.)
if (valueData == null) {
String valueType = (dataType == null) ? "NULL" : Types.getTypeName(dataType.typeCode);
exp.attributes.put("valuetype", valueType);
return exp;
}
exp.attributes.put("valuetype", Types.getTypeName(dataType.typeCode));
if (valueData instanceof TimestampData) {
// When we get the default from the DDL,
// it gets jammed into a TimestampData object. If we
// don't do this, we get a Java class/reference
// string in the output schema for the DDL.
// EL HACKO: I'm just adding in the timezone seconds
// at the moment, hope this is right --izzy
TimestampData time = (TimestampData) valueData;
exp.attributes.put("value", Long.toString(Math.round((time.getSeconds() + time.getZone()) * 1e6) + time.getNanos() / 1000));
return exp;
}
// convert binary values to hex
if (valueData instanceof BinaryData) {
BinaryData bd = (BinaryData) valueData;
exp.attributes.put("value", hexEncode(bd.getBytes()));
return exp;
}
// Otherwise just string format the value.
if (dataType instanceof NumberType && !dataType.isIntegralType()) {
// remove the scentific exponent notation
exp.attributes.put("value", new BigDecimal(valueData.toString()).toPlainString());
return exp;
}
exp.attributes.put("value", valueData.toString());
return exp;
case OpTypes.COLUMN:
ExpressionColumn ec = (ExpressionColumn) this;
return ec.voltAnnotateColumnXML(exp);
case OpTypes.COALESCE:
return convertUsingColumnrefToCoaleseExpression(context.m_session, exp, dataType);
case OpTypes.SQL_FUNCTION:
FunctionSQL fn = (FunctionSQL) this;
return fn.voltAnnotateFunctionXML(exp);
case OpTypes.COUNT:
case OpTypes.SUM:
case OpTypes.AVG:
if (((ExpressionAggregate) this).isDistinctAggregate) {
exp.attributes.put("distinct", "true");
}
return exp;
case OpTypes.ORDER_BY:
if (((ExpressionOrderBy) this).isDescending()) {
exp.attributes.put("desc", "true");
}
return exp;
case OpTypes.CAST:
if (dataType == null) {
throw new HSQLParseException("VoltDB could not determine the type in a CAST operation");
}
exp.attributes.put("valuetype", dataType.getNameString());
return exp;
case OpTypes.TABLE_SUBQUERY:
if (subQuery == null || subQuery.queryExpression == null) {
throw new HSQLParseException("VoltDB could not determine the subquery");
}
ExpressionColumn[] parameters = new ExpressionColumn[0];
exp.children.add(StatementQuery.voltGetXMLExpression(subQuery.queryExpression, parameters, context.m_session));
return exp;
case OpTypes.ALTERNATIVE:
assert (nodes.length == 2);
// If with ELSE clause, pad NULL with it.
if (nodes[RIGHT] instanceof ExpressionValue) {
ExpressionValue val = (ExpressionValue) nodes[RIGHT];
if (val.valueData == null && val.dataType == Type.SQL_ALL_TYPES) {
exp.children.get(RIGHT).attributes.put("valuetype", dataType.getNameString());
}
}
case OpTypes.CASEWHEN:
// Hsql has check dataType can not be null.
assert (dataType != null);
exp.attributes.put("valuetype", dataType.getNameString());
return exp;
case OpTypes.WINDOWED_RANK:
case OpTypes.WINDOWED_DENSE_RANK:
case OpTypes.WINDOWED_COUNT:
case OpTypes.WINDOWED_MIN:
case OpTypes.WINDOWED_MAX:
case OpTypes.WINDOWED_SUM:
assert (dataType != null);
assert (this instanceof ExpressionWindowed);
exp.attributes.put("valuetype", dataType.getNameString());
ExpressionWindowed erank = (ExpressionWindowed) this;
return erank.voltAnnotateWindowedAggregateXML(exp, context);
default:
return exp;
}
}
use of org.hsqldb_voltpatches.types.NumberType 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.NumberType in project voltdb by VoltDB.
the class DatabaseInformationFull method DOMAINS.
/**
* The DOMAINS view has one row for each domain. <p>
*
*
* <pre class="SqlCodeExample">
*
* </pre>
*
* @return Table
*/
Table DOMAINS() {
Table t = sysTables[DOMAINS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[DOMAINS]);
addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
addColumn(t, "DATA_TYPE", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DOMAIN_DEFAULT", CHARACTER_DATA);
addColumn(t, "MAXIMUM_CARDINALITY", SQL_IDENTIFIER);
addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCLAE", CARDINAL_NUMBER);
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[DOMAINS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 0, 1, 2, 4, 5, 6 }, false);
return t;
}
final int domain_catalog = 0;
final int domain_schema = 1;
final int domain_name = 2;
final int data_type = 3;
final int character_maximum_length = 4;
final int character_octet_length = 5;
final int character_set_catalog = 6;
final int character_set_schema = 7;
final int character_set_name = 8;
final int collation_catalog = 9;
final int collation_schema = 10;
final int collation_name = 11;
final int numeric_precision = 12;
final int numeric_precision_radix = 13;
final int numeric_scale = 14;
final int datetime_precision = 15;
final int interval_type = 16;
final int interval_precision = 17;
final int domain_default = 18;
final int maximum_cardinality = 19;
final int dtd_identifier = 20;
final int declared_data_type = 21;
final int declared_numeric_precision = 22;
final int declared_numeric_scale = 23;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
//
Iterator it = database.schemaManager.databaseObjectIterator(SchemaObject.DOMAIN);
while (it.hasNext()) {
Type domain = (Type) it.next();
if (!domain.isDomainType()) {
continue;
}
if (!session.getGrantee().isAccessible(domain)) {
continue;
}
Object[] data = t.getEmptyRowData();
data[domain_catalog] = database.getCatalogName().name;
data[domain_schema] = domain.getSchemaName().name;
data[domain_name] = domain.getName().name;
data[data_type] = domain.getFullNameString();
if (domain.isCharacterType()) {
data[character_maximum_length] = ValuePool.getLong(domain.precision);
data[character_octet_length] = ValuePool.getLong(domain.precision * 2);
data[character_set_catalog] = database.getCatalogName().name;
data[character_set_schema] = ((CharacterType) domain).getCharacterSet().getSchemaName().name;
data[character_set_name] = ((CharacterType) domain).getCharacterSet().getName().name;
data[collation_catalog] = database.getCatalogName().name;
data[collation_schema] = ((CharacterType) domain).getCollation().getSchemaName().name;
data[collation_name] = ((CharacterType) domain).getCollation().getName().name;
} else if (domain.isNumberType()) {
data[numeric_precision] = ValuePool.getLong(((NumberType) domain).getPrecision());
data[declared_numeric_precision] = data[numeric_precision];
if (domain.typeCode != Types.SQL_DOUBLE) {
data[numeric_scale] = ValuePool.getLong(domain.scale);
data[declared_numeric_scale] = data[numeric_scale];
}
data[numeric_precision_radix] = ValuePool.getLong(((NumberType) domain).getPrecisionRadix());
} else if (domain.isBooleanType()) {
} else if (domain.isDateTimeType()) {
data[datetime_precision] = ValuePool.getLong(domain.scale);
} else if (domain.isIntervalType()) {
data[interval_precision] = ValuePool.getLong(domain.precision);
data[interval_type] = domain.getFullNameString();
data[datetime_precision] = ValuePool.getLong(domain.scale);
} else if (domain.isBinaryType()) {
data[character_maximum_length] = ValuePool.getLong(domain.precision);
data[character_octet_length] = ValuePool.getLong(domain.precision);
} else if (domain.isBitType()) {
data[character_maximum_length] = ValuePool.getLong(domain.precision);
data[character_octet_length] = ValuePool.getLong(domain.precision);
}
Expression defaultExpression = domain.userTypeModifier.getDefaultClause();
if (defaultExpression != null) {
data[domain_default] = defaultExpression.getSQL();
}
t.insertSys(store, data);
}
return t;
}
use of org.hsqldb_voltpatches.types.NumberType in project voltdb by VoltDB.
the class DatabaseInformationFull method COLUMNS.
Table COLUMNS() {
Table t = sysTables[COLUMNS];
if (t == null) {
t = createBlankTable(sysTableHsqlNames[COLUMNS]);
//0
addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
addColumn(t, "ORDINAL_POSITION", CARDINAL_NUMBER);
addColumn(t, "COLUMN_DEFAULT", CHARACTER_DATA);
addColumn(t, "IS_NULLABLE", YES_OR_NO);
addColumn(t, "DATA_TYPE", CHARACTER_DATA);
addColumn(t, "CHARACTER_MAXIMUM_LENGTH", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_OCTET_LENGTH", CARDINAL_NUMBER);
//10
addColumn(t, "NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_PRECISION_RADIX", CARDINAL_NUMBER);
addColumn(t, "NUMERIC_SCALE", CARDINAL_NUMBER);
addColumn(t, "DATETIME_PRECISION", CARDINAL_NUMBER);
addColumn(t, "INTERVAL_TYPE", CHARACTER_DATA);
addColumn(t, "INTERVAL_PRECISION", CARDINAL_NUMBER);
addColumn(t, "CHARACTER_SET_CATALOG", CHARACTER_DATA);
addColumn(t, "CHARACTER_SET_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "CHARACTER_SET_NAME", SQL_IDENTIFIER);
addColumn(t, "COLLATION_CATALOG", SQL_IDENTIFIER);
//20
addColumn(t, "COLLATION_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "COLLATION_NAME", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_CATALOG", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "DOMAIN_NAME", SQL_IDENTIFIER);
addColumn(t, "UDT_CATALOG", SQL_IDENTIFIER);
addColumn(t, "UDT_SCHEMA", SQL_IDENTIFIER);
addColumn(t, "UDT_NAME", SQL_IDENTIFIER);
addColumn(t, "SCOPE_CATALOG", SQL_IDENTIFIER);
addColumn(t, "SCOPE_SCHEMA", SQL_IDENTIFIER);
//30
addColumn(t, "SCOPE_NAME", SQL_IDENTIFIER);
// NULL (only for array tyes)
addColumn(t, "MAXIMUM_CARDINALITY", CARDINAL_NUMBER);
addColumn(t, "DTD_IDENTIFIER", SQL_IDENTIFIER);
addColumn(t, "IS_SELF_REFERENCING", YES_OR_NO);
addColumn(t, "IS_IDENTITY", YES_OR_NO);
// ALLWAYS / BY DEFAULT
addColumn(t, "IDENTITY_GENERATION", CHARACTER_DATA);
addColumn(t, "IDENTITY_START", CHARACTER_DATA);
addColumn(t, "IDENTITY_INCREMENT", CHARACTER_DATA);
addColumn(t, "IDENTITY_MAXIMUM", CHARACTER_DATA);
addColumn(t, "IDENTITY_MINIMUM", CHARACTER_DATA);
//40
addColumn(t, "IDENTITY_CYCLE", YES_OR_NO);
// ALLWAYS / NEVER
addColumn(t, "IS_GENERATED", CHARACTER_DATA);
addColumn(t, "GENERATION_EXPRESSION", CHARACTER_DATA);
addColumn(t, "IS_UPDATABLE", YES_OR_NO);
addColumn(t, "DECLARED_DATA_TYPE", CHARACTER_DATA);
addColumn(t, "DECLARED_NUMERIC_PRECISION", CARDINAL_NUMBER);
addColumn(t, "DECLARED_NUMERIC_SCALE", CARDINAL_NUMBER);
// order: TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION
// added for unique: TABLE_CAT
// false PK, as TABLE_SCHEM and/or TABLE_CAT may be null
HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMNS].name, false, SchemaObject.INDEX);
t.createPrimaryKey(name, new int[] { 3, 2, 1, 4 }, false);
return t;
}
// column number mappings
final int table_cat = 0;
final int table_schem = 1;
final int table_name = 2;
final int column_name = 3;
final int ordinal_position = 4;
final int column_default = 5;
final int is_nullable = 6;
final int data_type = 7;
final int character_maximum_length = 8;
final int character_octet_length = 9;
final int numeric_precision = 10;
final int numeric_precision_radix = 11;
final int numeric_scale = 12;
final int datetime_precision = 13;
final int interval_type = 14;
final int interval_precision = 15;
final int character_set_catalog = 16;
final int character_set_schema = 17;
final int character_set_name = 18;
final int collation_catalog = 19;
final int collation_schema = 20;
final int collation_name = 21;
final int domain_catalog = 22;
final int domain_schema = 23;
final int domain_name = 24;
final int udt_catalog = 25;
final int udt_schema = 26;
final int udt_name = 27;
final int scope_catalog = 28;
final int scope_schema = 29;
final int scope_name = 30;
final int maximum_cardinality = 31;
final int dtd_identifier = 32;
final int is_self_referencing = 33;
final int is_identity = 34;
final int identity_generation = 35;
final int identity_start = 36;
final int identity_increment = 37;
final int identity_maximum = 38;
final int identity_minimum = 39;
final int identity_cycle = 40;
final int is_generated = 41;
final int generation_expression = 42;
final int is_updatable = 43;
final int declared_data_type = 44;
final int declared_numeric_precision = 45;
final int declared_numeric_scale = 46;
//
PersistentStore store = database.persistentStoreCollection.getStore(t);
// intermediate holders
int columnCount;
Iterator tables;
Table table;
Object[] row;
DITableInfo ti;
OrderedHashSet columnList;
Type type;
// Initialization
tables = allTables();
ti = new DITableInfo();
while (tables.hasNext()) {
table = (Table) tables.next();
columnList = session.getGrantee().getColumnsForAllPrivileges(table);
if (columnList.isEmpty()) {
continue;
}
ti.setTable(table);
columnCount = table.getColumnCount();
for (int i = 0; i < columnCount; i++) {
ColumnSchema column = table.getColumn(i);
type = column.getDataType();
if (!columnList.contains(column.getName())) {
continue;
}
row = t.getEmptyRowData();
row[table_cat] = table.getCatalogName().name;
row[table_schem] = table.getSchemaName().name;
row[table_name] = table.getName().name;
row[column_name] = column.getName().name;
row[ordinal_position] = ValuePool.getInt(i + 1);
row[column_default] = column.getDefaultSQL();
row[is_nullable] = column.isNullable() ? "YES" : "NO";
row[data_type] = type.getFullNameString();
if (type.isCharacterType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision * 2);
row[character_set_catalog] = database.getCatalogName().name;
row[character_set_schema] = ((CharacterType) type).getCharacterSet().getSchemaName().name;
row[character_set_name] = ((CharacterType) type).getCharacterSet().getName().name;
row[collation_catalog] = database.getCatalogName().name;
row[collation_schema] = ((CharacterType) type).getCollation().getSchemaName().name;
row[collation_name] = ((CharacterType) type).getCollation().getName().name;
}
if (type.isBinaryType()) {
row[character_maximum_length] = ValuePool.getLong(type.precision);
row[character_octet_length] = ValuePool.getLong(type.precision);
}
if (type.isNumberType()) {
row[numeric_precision] = ValuePool.getLong(type.precision);
row[numeric_precision_radix] = ValuePool.getLong(((NumberType) type).getPrecisionRadix());
row[numeric_scale] = ValuePool.getLong(type.scale);
}
if (type.isDateTimeType()) {
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isIntervalType()) {
row[interval_type] = IntervalType.getQualifier(type.typeCode);
row[interval_precision] = ValuePool.getLong(type.precision);
row[datetime_precision] = ValuePool.getLong(type.scale);
}
if (type.isDomainType()) {
row[domain_catalog] = database.getCatalogName().name;
row[domain_schema] = type.getSchemaName().name;
row[domain_name] = type.getName().name;
}
if (type.isDistinctType()) {
row[udt_catalog] = database.getCatalogName().name;
row[udt_schema] = type.getSchemaName().name;
row[udt_name] = type.getName().name;
}
row[scope_catalog] = null;
row[scope_schema] = null;
row[scope_name] = null;
row[maximum_cardinality] = null;
row[dtd_identifier] = null;
row[is_self_referencing] = null;
row[is_identity] = column.isIdentity() ? "YES" : "NO";
if (column.isIdentity()) {
NumberSequence sequence = column.getIdentitySequence();
row[identity_generation] = sequence.isAlways() ? "ALWAYS" : "BY DEFAULT";
row[identity_start] = Long.toString(sequence.getStartValue());
row[identity_increment] = Long.toString(sequence.getIncrement());
row[identity_maximum] = Long.toString(sequence.getMaxValue());
row[identity_minimum] = Long.toString(sequence.getMinValue());
row[identity_cycle] = sequence.isCycle() ? "YES" : "NO";
}
row[is_generated] = "NEVER";
row[generation_expression] = null;
row[is_updatable] = table.isWritable() ? "YES" : "NO";
row[declared_data_type] = row[data_type];
if (type.isNumberType()) {
row[declared_numeric_precision] = row[numeric_precision];
row[declared_numeric_scale] = row[numeric_scale];
}
t.insertSys(store, row);
}
}
return t;
}
Aggregations