use of org.gridgain.internal.h2.value.ValueString in project ignite by apache.
the class GridSqlFunction method getSQL.
/**
* {@inheritDoc}
*/
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder();
if (schema != null)
buff.append(Parser.quoteIdentifier(schema)).append('.');
// We don't need to quote identifier as long as H2 never does so with function names when generating plan SQL.
// On the other hand, quoting identifiers that also serve as keywords (like CURRENT_DATE() and CURRENT_DATE)
// turns CURRENT_DATE() into "CURRENT_DATE"(), which is not good.
buff.append(name);
if (type == CASE) {
buff.append(' ').append(child().getSQL());
for (int i = 1, len = size() - 1; i < len; i += 2) {
buff.append(" WHEN ").append(child(i).getSQL());
buff.append(" THEN ").append(child(i + 1).getSQL());
}
if ((size() & 1) == 0)
buff.append(" ELSE ").append(child(size() - 1).getSQL());
return buff.append(" END").toString();
}
buff.append('(');
switch(type) {
case CAST:
case CONVERT:
assert size() == 1;
String castType = resultType().sql();
assert !F.isEmpty(castType) : castType;
buff.append(child().getSQL());
buff.append(type == CAST ? " AS " : ",");
buff.append(castType);
break;
case EXTRACT:
ValueString v = (ValueString) ((GridSqlConst) child(0)).value();
buff.append(v.getString()).append(" FROM ").append(child(1).getSQL());
break;
case TABLE:
for (int i = 0; i < size(); i++) {
buff.appendExceptFirst(", ");
GridSqlElement e = child(i);
// id int = ?, name varchar = ('aaa', 'bbb')
buff.append(Parser.quoteIdentifier(((GridSqlAlias) e).alias())).append(' ').append(e.resultType().sql()).append('=').append(e.child().getSQL());
}
break;
default:
for (int i = 0; i < size(); i++) {
buff.appendExceptFirst(", ");
buff.append(child(i).getSQL());
}
}
return buff.append(')').toString();
}
use of org.gridgain.internal.h2.value.ValueString in project h2database by h2database.
the class Function method getSQL.
@Override
public String getSQL() {
StatementBuilder buff = new StatementBuilder(info.name);
if (info.type == CASE) {
if (args[0] != null) {
buff.append(" ").append(args[0].getSQL());
}
for (int i = 1, len = args.length - 1; i < len; i += 2) {
buff.append(" WHEN ").append(args[i].getSQL());
buff.append(" THEN ").append(args[i + 1].getSQL());
}
if (args.length % 2 == 0) {
buff.append(" ELSE ").append(args[args.length - 1].getSQL());
}
return buff.append(" END").toString();
}
buff.append('(');
switch(info.type) {
case CAST:
{
buff.append(args[0].getSQL()).append(" AS ").append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
break;
}
case CONVERT:
{
if (database.getMode().swapConvertFunctionParameters) {
buff.append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL()).append(',').append(args[0].getSQL());
} else {
buff.append(args[0].getSQL()).append(',').append(new Column(null, dataType, precision, scale, displaySize).getCreateSQL());
}
break;
}
case EXTRACT:
{
ValueString v = (ValueString) ((ValueExpression) args[0]).getValue(null);
buff.append(v.getString()).append(" FROM ").append(args[1].getSQL());
break;
}
default:
{
for (Expression e : args) {
buff.appendExceptFirst(", ");
buff.append(e.getSQL());
}
}
}
return buff.append(')').toString();
}
use of org.gridgain.internal.h2.value.ValueString in project gridgain by gridgain.
the class ResultWithPaddedStrings method currentRow.
@Override
public Value[] currentRow() {
int count = source.getVisibleColumnCount();
Value[] row = Arrays.copyOf(source.currentRow(), count);
for (int i = 0; i < count; i++) {
TypeInfo type = source.getColumnType(i);
if (type.getValueType() == Value.STRING_FIXED) {
long precision = type.getPrecision();
if (precision == Integer.MAX_VALUE) {
// CHAR is CHAR(1)
precision = 1;
}
String s = row[i].getString();
if (s != null && s.length() < precision) {
/*
* Use ValueString to avoid truncation of spaces. There is
* no difference between ValueStringFixed and ValueString
* for JDBC layer anyway.
*/
row[i] = ValueString.get(rightPadWithSpaces(s, MathUtils.convertLongToInt(precision)));
}
}
}
return row;
}
use of org.gridgain.internal.h2.value.ValueString in project gridgain by gridgain.
the class GridSqlFunction method getSQL.
/**
* {@inheritDoc}
*/
@Override
public String getSQL() {
StringBuilder buff = new StringBuilder();
if (schema != null) {
Parser.quoteIdentifier(buff, schema, true);
buff.append('.');
}
// We don't need to quote identifier as long as H2 never does so with function names when generating plan SQL.
// On the other hand, quoting identifiers that also serve as keywords (like CURRENT_DATE() and CURRENT_DATE)
// turns CURRENT_DATE() into "CURRENT_DATE"(), which is not good.
buff.append(name);
if (type == CASE) {
buff.append(' ').append(child().getSQL());
for (int i = 1, len = size() - 1; i < len; i += 2) {
buff.append(" WHEN ").append(child(i).getSQL());
buff.append(" THEN ").append(child(i + 1).getSQL());
}
if ((size() & 1) == 0)
buff.append(" ELSE ").append(child(size() - 1).getSQL());
return buff.append(" END").toString();
}
buff.append('(');
switch(type) {
case CAST:
case CONVERT:
assert size() == 1;
String castType = resultType().sql();
assert !F.isEmpty(castType) : castType;
buff.append(child().getSQL());
buff.append(type == CAST ? " AS " : ",");
buff.append(castType);
break;
case EXTRACT:
ValueString v = (ValueString) ((GridSqlConst) child(0)).value();
buff.append(v.getString()).append(" FROM ").append(child(1).getSQL());
break;
case TABLE:
for (int i = 0; i < size(); i++) {
if (i > 0)
buff.append(", ");
GridSqlElement e = child(i);
// id int = ?, name varchar = ('aaa', 'bbb')
Parser.quoteIdentifier(buff, ((GridSqlAlias) e).alias(), true);
buff.append(' ').append(e.resultType().sql()).append('=').append(e.child().getSQL());
}
break;
default:
for (int i = 0; i < size(); i++) {
if (i > 0)
buff.append(", ");
buff.append(child(i).getSQL());
}
}
return buff.append(')').toString();
}
use of org.gridgain.internal.h2.value.ValueString in project gridgain by gridgain.
the class Function method getSQL.
@Override
public StringBuilder getSQL(StringBuilder builder, boolean alwaysQuote) {
builder.append(info.name);
if (info.type == CASE) {
if (args[0] != null) {
builder.append(' ');
args[0].getSQL(builder, alwaysQuote);
}
for (int i = 1, len = args.length - 1; i < len; i += 2) {
builder.append(" WHEN ");
args[i].getSQL(builder, alwaysQuote);
builder.append(" THEN ");
args[i + 1].getSQL(builder, alwaysQuote);
}
if (args.length % 2 == 0) {
builder.append(" ELSE ");
args[args.length - 1].getSQL(builder, alwaysQuote);
}
return builder.append(" END");
}
boolean addParentheses = args.length > 0 || info.requireParentheses;
if (addParentheses) {
builder.append('(');
}
switch(info.type) {
case CAST:
{
args[0].getSQL(builder, alwaysQuote).append(" AS ").append(new Column(null, type).getCreateSQL());
break;
}
case CONVERT:
{
if (database.getMode().swapConvertFunctionParameters) {
builder.append(new Column(null, type).getCreateSQL()).append(',');
args[0].getSQL(builder, alwaysQuote);
} else {
args[0].getSQL(builder, alwaysQuote).append(',').append(new Column(null, type).getCreateSQL());
}
break;
}
case EXTRACT:
{
ValueString v = (ValueString) ((ValueExpression) args[0]).getValue(null);
builder.append(v.getString()).append(" FROM ");
args[1].getSQL(builder, alwaysQuote);
break;
}
default:
writeExpressions(builder, args, alwaysQuote);
}
if (addParentheses) {
builder.append(')');
}
return builder;
}
Aggregations