com.alibaba.druid.sql.ast.expr.SQLValuableExpr Java Examples
The following examples show how to use
com.alibaba.druid.sql.ast.expr.SQLValuableExpr.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java From elasticsearch-sql with Apache License 2.0 | 6 votes |
public static Object expr2Object(SQLExpr expr, String charWithQuote) { Object value = null; if (expr instanceof SQLNumericLiteralExpr) { value = ((SQLNumericLiteralExpr) expr).getNumber(); } else if (expr instanceof SQLCharExpr) { value = charWithQuote + ((SQLCharExpr) expr).getText() + charWithQuote; } else if (expr instanceof SQLIdentifierExpr) { value = expr.toString(); } else if (expr instanceof SQLPropertyExpr) { value = expr.toString(); } else if (expr instanceof SQLVariantRefExpr) { value = expr.toString(); } else if (expr instanceof SQLAllColumnExpr) { value = "*"; } else if (expr instanceof SQLValuableExpr) { value = ((SQLValuableExpr) expr).getValue(); } else if (expr instanceof SQLBooleanExpr) { value = ((SQLBooleanExpr) expr).getValue(); } else { //throw new SqlParseException("can not support this type " + expr.getClass()); } return value; }
Example #2
Source File: UpdateParser.java From dts with Apache License 2.0 | 5 votes |
@Override public TableDataInfo getPresentValue(List<Object> sqlParamsList, SQLUpdateStatement parseSqlStatement, StatementAdapter statementAdapter, TableMetaInfo tableMetaInfo) throws SQLException { TableDataInfo txcTable = new TableDataInfo(); txcTable.setTableName(parseSqlStatement.getTableName().getSimpleName()); TxcLine txcLine = new TxcLine(); List<SQLUpdateSetItem> items = parseSqlStatement.getItems(); int variantExpr = 0; for (int i = 0; i < items.size(); i++) { SQLUpdateSetItem sqlUpdateSetItem = items.get(i); TxcField txcField = new TxcField(); String cloumnName = SQLUtils.toSQLString(sqlUpdateSetItem.getColumn()).replace("\'", "").replace("`", "").trim(); txcField.setName(cloumnName); if (sqlUpdateSetItem.getValue() instanceof SQLVariantRefExpr) { txcField.setValue(sqlParamsList.get(variantExpr++)); } else if (sqlUpdateSetItem.getValue() instanceof SQLValuableExpr) { txcField.setValue(SQLUtils.toSQLString(items.get(i).getValue())); } else { throw new UnsupportedOperationException( String.format("Do not support complex sql,%s", sqlUpdateSetItem.getClass().toString())); } txcField.setJdkValue(SerializeUtils.serialize(txcField.getValue())); txcLine.getFields().add(txcField); } txcTable.getLine().add(txcLine); return txcTable; }
Example #3
Source File: SQLInExprWrapper.java From Zebra with Apache License 2.0 | 5 votes |
@Override public int hashCode() { if (!initHash) { if (sqlExpr instanceof SQLValuableExpr) { hash = sqlExpr.hashCode(); } else if (sqlExpr instanceof SQLVariantRefExpr) { SQLVariantRefExpr ref = (SQLVariantRefExpr) sqlExpr; hash = ref.hashCode() * 31 + ref.getIndex(); valueRefSet.add(ref.getIndex()); } else if (sqlExpr instanceof SQLListExpr) { SQLListExpr listExpr = (SQLListExpr) sqlExpr; List<SQLExpr> items = listExpr.getItems(); hash = 1; if (items != null) { for (SQLExpr expr : items) { if (expr instanceof SQLVariantRefExpr) { hash = (hash * 31 + expr.hashCode()) * 31 + ((SQLVariantRefExpr) expr).getIndex(); valueRefSet.add(((SQLVariantRefExpr) expr).getIndex()); } else { hash = hash * 31 + expr.hashCode(); } } } } initValueRefSet = true; initHash = true; } return hash; }
Example #4
Source File: Util.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
public static Object getScriptValue(SQLExpr expr) throws SqlParseException { if (expr instanceof SQLIdentifierExpr || expr instanceof SQLPropertyExpr || expr instanceof SQLVariantRefExpr) { return "doc['" + expr.toString() + "'].value"; } else if (expr instanceof SQLValuableExpr) { return ((SQLValuableExpr) expr).getValue(); } throw new SqlParseException("could not parse sqlBinaryOpExpr need to be identifier/valuable got" + expr.getClass().toString() + " with value:" + expr.toString()); }