use of net.sf.jsqlparser.expression.LongValue in project spanner-jdbc by olavloite.
the class AbstractSpannerExpressionVisitorAdapter method visit.
@Override
public void visit(SignedExpression value) {
Expression underlyingValue = value.getExpression();
if (underlyingValue instanceof DoubleValue) {
DoubleValue doubleValue = (DoubleValue) underlyingValue;
doubleValue.setValue(value.getSign() == '-' ? -doubleValue.getValue() : doubleValue.getValue());
visit(doubleValue);
} else if (underlyingValue instanceof LongValue) {
LongValue longValue = (LongValue) underlyingValue;
longValue.setValue(value.getSign() == '-' ? -longValue.getValue() : longValue.getValue());
visit(longValue);
} else {
super.visit(value);
}
}
use of net.sf.jsqlparser.expression.LongValue in project dbeaver by dbeaver.
the class QueryTransformerTop method transformQueryString.
@Override
public String transformQueryString(SQLQuery query) throws DBCException {
limitSet = false;
if (query.isPlainSelect()) {
try {
Statement statement = query.getStatement();
if (statement instanceof Select) {
Select select = (Select) statement;
if (select.getSelectBody() instanceof PlainSelect) {
PlainSelect selectBody = (PlainSelect) select.getSelectBody();
if (selectBody.getTop() == null && CommonUtils.isEmpty(selectBody.getIntoTables())) {
Top top = new Top();
top.setPercentage(false);
top.setExpression(new LongValue(offset.longValue() + length.longValue()));
selectBody.setTop(top);
limitSet = true;
return statement.toString();
}
}
}
} catch (Throwable e) {
// ignore
log.debug(e);
}
}
return query.getText();
}
use of net.sf.jsqlparser.expression.LongValue in project herddb by diennea.
the class SQLExpressionCompiler method compileExpression.
// this method never returns NULL
public static CompiledSQLExpression compileExpression(String validatedTableAlias, Expression exp) {
if (exp instanceof BinaryExpression) {
CompiledSQLExpression compiled = compileSpecialBinaryExpression(validatedTableAlias, exp);
if (compiled != null) {
return compiled;
}
}
if (exp instanceof net.sf.jsqlparser.schema.Column) {
return compileColumnExpression(validatedTableAlias, exp);
} else if (exp instanceof StringValue) {
return new ConstantExpression(RawString.of(((StringValue) exp).getValue()));
} else if (exp instanceof LongValue) {
try {
return new ConstantExpression(((LongValue) exp).getValue());
} catch (NumberFormatException largeNumber) {
return new ConstantExpression(Double.valueOf(((LongValue) exp).getStringValue()));
}
} else if (exp instanceof DoubleValue) {
return new ConstantExpression(((DoubleValue) exp).getValue());
} else if (exp instanceof TimestampValue) {
return new ConstantExpression(((TimestampValue) exp).getValue());
} else if (exp instanceof NullValue) {
return new ConstantExpression(null);
} else if (exp instanceof TimeKeyExpression) {
TimeKeyExpression ext = (TimeKeyExpression) exp;
if (CURRENT_TIMESTAMP.equalsIgnoreCase(ext.getStringValue())) {
return new ConstantExpression(new java.sql.Timestamp(System.currentTimeMillis()));
} else {
throw new StatementExecutionException("unhandled expression " + exp);
}
} else if (exp instanceof JdbcParameter) {
int index = ((JdbcParameter) exp).getIndex() - 1;
return new JdbcParameterExpression(index);
} else if (exp instanceof AndExpression) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledAndExpression(a, b, c));
} else if (exp instanceof OrExpression) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledOrExpression(a, b, c));
} else if (exp instanceof Function) {
return CompiledFunction.create((Function) exp, validatedTableAlias);
} else if (exp instanceof Addition) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledAddExpression(a, b, c));
} else if (exp instanceof Subtraction) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledSubtractExpression(a, b, c));
} else if (exp instanceof Multiplication) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledMultiplyExpression(a, b, c));
} else if (exp instanceof Division) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledDivideExpression(a, b, c));
} else if (exp instanceof Parenthesis) {
Parenthesis p = (Parenthesis) exp;
CompiledSQLExpression inner = compileExpression(validatedTableAlias, p.getExpression());
return new CompiledParenthesisExpression(p.isNot(), inner);
} else if (exp instanceof EqualsTo) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledEqualsExpression(a, b, c));
} else if (exp instanceof NotEqualsTo) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledNotEqualsExpression(a, b, c));
} else if (exp instanceof MinorThan) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledMinorThenExpression(a, b, c));
} else if (exp instanceof MinorThanEquals) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledMinorThenEqualsExpression(a, b, c));
} else if (exp instanceof GreaterThan) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledGreaterThenExpression(a, b, c));
} else if (exp instanceof GreaterThanEquals) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledGreaterThenEqualsExpression(a, b, c));
} else if (exp instanceof LikeExpression) {
return tryCompileBinaryExpression(validatedTableAlias, (BinaryExpression) exp, (a, b, c) -> new CompiledLikeExpression(a, b, c));
} else if (exp instanceof Between) {
return CompiledBetweenExpression.create(validatedTableAlias, (Between) exp);
} else if (exp instanceof SignedExpression) {
SignedExpression s = (SignedExpression) exp;
CompiledSQLExpression inner = compileExpression(validatedTableAlias, s.getExpression());
return new CompiledSignedExpression(s.getSign(), inner);
} else if (exp instanceof InExpression) {
InExpression in = (InExpression) exp;
return CompiledInExpression.create(in, validatedTableAlias);
} else if (exp instanceof IsNullExpression) {
IsNullExpression i = (IsNullExpression) exp;
CompiledSQLExpression left = compileExpression(validatedTableAlias, i.getLeftExpression());
return new CompiledIsNullExpression(i.isNot(), left);
} else if (exp instanceof CaseExpression) {
return CompiledCaseExpression.create(validatedTableAlias, (CaseExpression) exp);
}
throw new StatementExecutionException("unsupported operand " + exp.getClass() + ", expression is " + exp);
}
use of net.sf.jsqlparser.expression.LongValue in project JSqlParser by JSQLParser.
the class CCJSqlParserUtilTest method testParseExpression2.
@Test
public void testParseExpression2() throws Exception {
Expression result = CCJSqlParserUtil.parseExpression("2*(a+6.0)");
assertEquals("2 * (a + 6.0)", result.toString());
assertTrue(result instanceof Multiplication);
Multiplication mult = (Multiplication) result;
assertTrue(mult.getLeftExpression() instanceof LongValue);
assertTrue(mult.getRightExpression() instanceof Parenthesis);
}
use of net.sf.jsqlparser.expression.LongValue in project dbeaver by serge-rider.
the class SQLSemanticProcessor method getConstraintExpression.
private static Expression getConstraintExpression(PlainSelect select, DBDAttributeConstraint co) throws JSQLParserException {
Expression orderExpr;
String attrName = co.getAttribute().getName();
if (attrName.isEmpty()) {
orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
} else if (CommonUtils.isJavaIdentifier(attrName)) {
// Use column table only if there are multiple source tables (joins)
Table orderTable = CommonUtils.isEmpty(select.getJoins()) ? null : getConstraintTable(select, co);
orderExpr = new Column(orderTable, attrName);
} else {
// TODO: set tableAlias for all column references in expression
orderExpr = CCJSqlParserUtil.parseExpression(attrName);
//orderExpr = new CustomExpression(attrName);
//orderExpr = new LongValue(co.getAttribute().getOrdinalPosition() + 1);
}
return orderExpr;
}
Aggregations