public LiteralParseNode literal(Object value) { return new LiteralParseNode(value); }
protected CreateSequenceStatement(TableName sequenceName, ParseNode startWith, ParseNode incrementBy, ParseNode cacheSize, ParseNode minValue, ParseNode maxValue, boolean cycle, boolean ifNotExists, int bindCount) { this.sequenceName = sequenceName; // if MINVALUE, MAXVALUE and START WITH are not specified, set START WITH to 1 in order to // maintain backward compatibility this.startWith = (minValue == null && maxValue == null && startWith == null) ? LiteralParseNode.ONE : startWith; this.minValue = minValue == null ? new LiteralParseNode(Long.MIN_VALUE) : minValue; this.maxValue = maxValue == null ? new LiteralParseNode(Long.MAX_VALUE) : maxValue; this.incrementBy = incrementBy == null ? LiteralParseNode.ONE : incrementBy; this.cacheSize = cacheSize; this.cycle = cycle; this.ifNotExists = ifNotExists; this.bindCount = bindCount; }
public LiteralParseNode intOrLong(String text) { long l = Long.parseLong(text); if (l <= Integer.MAX_VALUE) { // Fits into int return new LiteralParseNode((int)l); } return new LiteralParseNode(l); }
public LiteralParseNode realNumber(String text) { return new LiteralParseNode(new BigDecimal(text, PDataType.DEFAULT_MATH_CONTEXT)); }
public LiteralParseNode wholeNumber(String text) { int length = text.length(); // We know it'll fit into long, might still fit into int if (length <= PDataType.LONG_PRECISION-1) { long l = Long.parseLong(text); if (l <= Integer.MAX_VALUE) { // Fits into int return new LiteralParseNode((int)l); } return new LiteralParseNode(l); } // Might still fit into long BigDecimal d = new BigDecimal(text, PDataType.DEFAULT_MATH_CONTEXT); if (d.compareTo(MAX_LONG) <= 0) { return new LiteralParseNode(d.longValueExact()); } // Doesn't fit into long return new LiteralParseNode(d); }
private static LiteralParseNode getNodeForRowTimestampColumn(PColumn col) { PDataType type = col.getDataType(); long dummyValue = 0L; if (type.isCoercibleTo(PTimestamp.INSTANCE)) { return new LiteralParseNode(new Timestamp(dummyValue), PTimestamp.INSTANCE); } else if (type == PLong.INSTANCE || type == PUnsignedLong.INSTANCE) { return new LiteralParseNode(dummyValue, PLong.INSTANCE); } throw new IllegalArgumentException(); }
public FunctionParseNode function(String name, List<ParseNode> valueNodes, List<ParseNode> columnNodes, boolean isAscending) { List<ParseNode> args = Lists.newArrayListWithExpectedSize(columnNodes.size() + valueNodes.size() + 1); args.addAll(columnNodes); args.add(new LiteralParseNode(Boolean.valueOf(isAscending))); args.addAll(valueNodes); BuiltInFunctionInfo info = getInfo(name, args); if(info==null) { return new UDFParseNode(name,args,info); } Constructor<? extends FunctionParseNode> ctor = info.getNodeCtor(); if (ctor == null) { return new AggregateFunctionWithinGroupParseNode(name, args, info); } else { try { return ctor.newInstance(name, args, info); } catch (Exception e) { throw new RuntimeException(e); } } }
private static SelectStatement prependTenantAndViewConstants(PTable table, SelectStatement select, String tenantId, Set<PColumn> addViewColumns, boolean useServerTimestamp) { if ((!table.isMultiTenant() || tenantId == null) && table.getViewIndexId() == null && addViewColumns.isEmpty() && !useServerTimestamp) { return select; } List<AliasedNode> selectNodes = newArrayListWithCapacity(select.getSelect().size() + 1 + addViewColumns.size()); if (table.getViewIndexId() != null) { selectNodes.add(new AliasedNode(null, new LiteralParseNode(table.getViewIndexId()))); } if (table.isMultiTenant() && tenantId != null) { selectNodes.add(new AliasedNode(null, new LiteralParseNode(tenantId))); } selectNodes.addAll(select.getSelect()); for (PColumn column : addViewColumns) { byte[] byteValue = column.getViewConstant(); Object value = column.getDataType().toObject(byteValue, 0, byteValue.length-1); selectNodes.add(new AliasedNode(null, new LiteralParseNode(value))); } if (useServerTimestamp) { PColumn rowTimestampCol = table.getPKColumns().get(table.getRowTimestampColPos()); selectNodes.add(new AliasedNode(null, getNodeForRowTimestampColumn(rowTimestampCol))); } return SelectStatement.create(select, selectNodes); }
public LiteralParseNode literal(Object value, PDataType expectedType) throws SQLException { PDataType actualType = PDataType.fromLiteral(value); if (actualType != null && actualType != expectedType) { checkTypeMatch(expectedType, actualType); value = expectedType.toObject(value, actualType); } return new LiteralParseNode(value); /* Object typedValue = expectedType.toObject(value.toString()); return new LiteralParseNode(typedValue); */ }
public LiteralParseNode literal(String value, String sqlTypeName) throws SQLException { PDataType expectedType = sqlTypeName == null ? null : PDataType.fromSqlTypeName(SchemaUtil.normalizeIdentifier(sqlTypeName)); if (expectedType == null || !expectedType.isCoercibleTo(PTimestamp.INSTANCE)) { throw TypeMismatchException.newException(expectedType, PTimestamp.INSTANCE); } Object typedValue = expectedType.toObject(value); return new LiteralParseNode(typedValue); }
FunctionArgument arg = new FunctionArgument(type.getString(), isArrayType, isConstant, defaultValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(defaultValue)).getValue()), minValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(minValue)).getValue()), maxValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(maxValue)).getValue()), argPosition); arguments.add(arg);
String maxValue = arg.hasMaxValue()?arg.getMaxValue():null; args.add(new FunctionArgument(argType, isArrayType, isConstant, defaultValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(defaultValue))).getValue()), minValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(minValue))).getValue()), maxValue == null ? null : LiteralExpression.newConstant((new LiteralParseNode(dataType.toObject(maxValue))).getValue())));
public LiteralParseNode intOrLong(String text) { long l = Long.parseLong(text); if (l <= Integer.MAX_VALUE) { // Fits into int return new LiteralParseNode((int)l); } return new LiteralParseNode(l); }
private static LiteralParseNode getNodeForRowTimestampColumn(PColumn col) { PDataType type = col.getDataType(); long dummyValue = 0L; if (type.isCoercibleTo(PTimestamp.INSTANCE)) { return new LiteralParseNode(new Timestamp(dummyValue), PTimestamp.INSTANCE); } else if (type == PLong.INSTANCE || type == PUnsignedLong.INSTANCE) { return new LiteralParseNode(dummyValue, PLong.INSTANCE); } throw new IllegalArgumentException(); }
private static LiteralParseNode getNodeForRowTimestampColumn(PColumn col) { PDataType type = col.getDataType(); long dummyValue = 0L; if (type.isCoercibleTo(PTimestamp.INSTANCE)) { return new LiteralParseNode(new Timestamp(dummyValue), PTimestamp.INSTANCE); } else if (type == PLong.INSTANCE || type == PUnsignedLong.INSTANCE) { return new LiteralParseNode(dummyValue, PLong.INSTANCE); } throw new IllegalArgumentException(); }
return new LiteralParseNode(literal, dataCol.getDataType());
public LiteralParseNode literal(Object value, PDataType expectedType) throws SQLException { PDataType actualType = PDataType.fromLiteral(value); if (actualType != null && actualType != expectedType) { checkTypeMatch(expectedType, actualType); value = expectedType.toObject(value, actualType); } return new LiteralParseNode(value); /* Object typedValue = expectedType.toObject(value.toString()); return new LiteralParseNode(typedValue); */ }
public LiteralParseNode literal(Object value, PDataType expectedType) throws SQLException { PDataType actualType = PDataType.fromLiteral(value); if (actualType != null && actualType != expectedType) { checkTypeMatch(expectedType, actualType); value = expectedType.toObject(value, actualType); } return new LiteralParseNode(value); /* Object typedValue = expectedType.toObject(value.toString()); return new LiteralParseNode(typedValue); */ }
public LiteralParseNode literal(String value, String sqlTypeName) throws SQLException { PDataType expectedType = sqlTypeName == null ? null : PDataType.fromSqlTypeName(SchemaUtil.normalizeIdentifier(sqlTypeName)); if (expectedType == null || !expectedType.isCoercibleTo(PTimestamp.INSTANCE)) { throw TypeMismatchException.newException(expectedType, PTimestamp.INSTANCE); } Object typedValue = expectedType.toObject(value); return new LiteralParseNode(typedValue); }
public LiteralParseNode literal(String value, String sqlTypeName) throws SQLException { PDataType expectedType = sqlTypeName == null ? null : PDataType.fromSqlTypeName(SchemaUtil.normalizeIdentifier(sqlTypeName)); if (expectedType == null || !expectedType.isCoercibleTo(PTimestamp.INSTANCE)) { throw TypeMismatchException.newException(expectedType, PTimestamp.INSTANCE); } Object typedValue = expectedType.toObject(value); return new LiteralParseNode(typedValue); }