Java Code Examples for com.alibaba.druid.sql.ast.expr.SQLIntegerExpr#getNumber()
The following examples show how to use
com.alibaba.druid.sql.ast.expr.SQLIntegerExpr#getNumber() .
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: DruidInsertParser.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
private String getShardingValue(SQLExpr expr) throws SQLNonTransientException { String shardingValue = null; if(expr instanceof SQLIntegerExpr) { SQLIntegerExpr intExpr = (SQLIntegerExpr)expr; shardingValue = intExpr.getNumber() + ""; } else if (expr instanceof SQLCharExpr) { SQLCharExpr charExpr = (SQLCharExpr)expr; shardingValue = charExpr.getText(); } else if (expr instanceof SQLMethodInvokeExpr) { SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr)expr; try { shardingValue = tryInvokeSQLMethod(methodInvokeExpr); }catch (Exception e){ LOGGER.error("",e); } if (shardingValue == null){ shardingValue = expr.toString(); } } else { shardingValue = expr.toString(); } return shardingValue; }
Example 2
Source File: ShardingValuesHandler.java From dble with GNU General Public License v2.0 | 5 votes |
private Integer handleShardingColumn(DumpFileContext context, List<SQLExpr> values) throws SQLNonTransientException { AbstractPartitionAlgorithm algorithm = context.getTableConfig().getRule().getRuleAlgorithm(); SQLExpr expr = values.get(context.getPartitionColumnIndex()); String shardingValue = null; if (expr instanceof SQLIntegerExpr) { SQLIntegerExpr intExpr = (SQLIntegerExpr) expr; shardingValue = intExpr.getNumber() + ""; } else if (expr instanceof SQLCharExpr) { SQLCharExpr charExpr = (SQLCharExpr) expr; shardingValue = charExpr.getText(); } if (shardingValue == null && !(expr instanceof SQLNullExpr)) { throw new SQLNonTransientException("Not Supported of Sharding Value EXPR :" + values.toString()); } Integer nodeIndex; try { nodeIndex = algorithm.calculate(shardingValue); // null means can't find any valid index if (nodeIndex == null || nodeIndex >= context.getTableConfig().getDataNodes().size()) { throw new SQLNonTransientException("can't find any valid datanode shardingValue" + values.toString()); } } catch (Exception e) { throw new SQLNonTransientException("can't calculate valid datanode shardingValue" + values.toString() + ",due to " + e.getMessage()); } return nodeIndex; }
Example 3
Source File: DruidInsertReplaceParser.java From dble with GNU General Public License v2.0 | 5 votes |
static String shardingValueToSting(SQLExpr valueExpr) throws SQLNonTransientException { String shardingValue = null; if (valueExpr instanceof SQLIntegerExpr) { SQLIntegerExpr intExpr = (SQLIntegerExpr) valueExpr; shardingValue = intExpr.getNumber() + ""; } else if (valueExpr instanceof SQLCharExpr) { SQLCharExpr charExpr = (SQLCharExpr) valueExpr; shardingValue = charExpr.getText(); } if (shardingValue == null && !(valueExpr instanceof SQLNullExpr)) { throw new SQLNonTransientException("Not Supported of Sharding Value EXPR :" + valueExpr.toString()); } return shardingValue; }
Example 4
Source File: MysqlMethodInvocationHandler.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
private SQLExpr invokeAddDate(SQLMethodInvokeExpr expr, boolean negative) throws SQLNonTransientException { List<SQLExpr> parameters = expr.getParameters(); if (parameters.size() != 2) { throwSyntaxError(expr); } SQLExpr p1 = parameters.get(0); SQLExpr p2 = parameters.get(1); if (p1 instanceof SQLMethodInvokeExpr) { p1 = doInvoke((SQLMethodInvokeExpr) p1); } if (p1 instanceof SQLCharExpr) { String time = ((SQLCharExpr) p1).getText(); Integer delta = null; String unit = null; if (p2 instanceof SQLIntegerExpr) { delta = (Integer) ((SQLIntegerExpr) p2).getNumber(); unit = "DAY"; } else if (p2 instanceof MySqlIntervalExpr) { SQLIntegerExpr value = (SQLIntegerExpr) ((MySqlIntervalExpr) p2).getValue(); delta = (Integer) value.getNumber(); unit = ((MySqlIntervalExpr) p2).getUnit().name(); } else { throwSyntaxError(p2); } try { Date date = DateUtils.parseDate(time, SUPPORT_PATTERNS); Date result; delta = negative ? -delta : delta; if ("MONTH".equals(unit)) { result = DateUtils.addMonths(date, delta); } else if ("DAY".equals(unit)) { result = DateUtils.addDays(date, delta); } else if ("HOUR".equals(unit)) { result = DateUtils.addHours(date, delta); } else if ("MINUTE".equals(unit)) { result = DateUtils.addMinutes(date, delta); } else if ("SECOND".equals(unit)) { result = DateUtils.addSeconds(date, delta); } else { return null; } String ret = DateFormatUtils.format(result, "yyyy-MM-dd HH:mm:ss"); return new SQLIdentifierExpr(ret); } catch (ParseException e) { LOGGER.error("",e); } } return null; }