本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.IFunction.setArgs方法的典型用法代码示例。如果您正苦于以下问题:Java IFunction.setArgs方法的具体用法?Java IFunction.setArgs怎么用?Java IFunction.setArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.core.expression.IFunction
的用法示例。
在下文中一共展示了IFunction.setArgs方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRowFunction
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private IFunction buildRowFunction(Collection values, boolean isColumn, CloneableRecord record) {
IFunction func = ASTNodeFactory.getInstance().createFunction();
func.setFunctionName("ROW");
StringBuilder columnName = new StringBuilder();
columnName.append('(').append(StringUtils.join(values, ',')).append(')');
func.setColumnName(columnName.toString());
if (isColumn) {
List<IColumn> columns = new ArrayList<IColumn>(values.size());
for (Object value : values) {
IColumn col = ASTNodeFactory.getInstance()
.createColumn()
.setColumnName((String) value)
.setDataType(record.getType((String) value));
columns.add(col);
}
func.setArgs(columns);
} else {
func.setArgs(new ArrayList(values));
}
return func;
}
示例2: testDistinct
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testDistinct() throws SqlParserException, QueryException {
String sql = "SELECT COUNT(DISTINCT ID) FROM TABLE1";
QueryTreeNode qn = query(sql);
TableNode table1 = new TableNode("TABLE1");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
c.setDistinct(true);
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
f.setColumnName("COUNT(DISTINCT ID)");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
qn.build();
QueryTreeNode qnExpected = table1.select(f);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例3: visit
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public void visit(FunctionExpression node) {
boolean argDistinct = isDistinct(node);
IFunction ifunc = ASTNodeFactory.getInstance().createFunction();
ifunc.setFunctionName(node.getFunctionName());
List<Expression> expressions = node.getArguments();
if (expressions != null) {
ArrayList<Object> args = new ArrayList<Object>();
for (Expression expr : expressions) {
MySqlExprVisitor v = new MySqlExprVisitor(parent);
expr.accept(v);
Object cv = v.getColumnOrValue();
if ((cv instanceof ISelectable)) {
((ISelectable) cv).setDistinct(argDistinct);
}
args.add(v.getColumnOrValue());
}
ifunc.setArgs(args);
} else {
ifunc.setArgs(new ArrayList());
}
ifunc.setColumnName(getSqlExprStr(node));
columnOrValue = ifunc;
}
示例4: handleArithmetric
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private void handleArithmetric(BinaryOperatorExpression expr, String functionName) {
IFunction func = ASTNodeFactory.getInstance().createFunction();
func.setFunctionName(functionName);
List<Object> args = new ArrayList<Object>(2);
MySqlExprVisitor leftevi = new MySqlExprVisitor();
expr.getLeftOprand().accept(leftevi);
args.add(leftevi.getColumnOrValue());
MySqlExprVisitor rightevi = new MySqlExprVisitor();
expr.getRightOprand().accept(rightevi);
args.add(rightevi.getColumnOrValue());
func.setArgs(args); // 设置参数
func.setColumnName(getSqlExprStr(expr));
this.columnOrValue = func;
}
示例5: copy
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public RT copy() {
IFunction funcNew = ASTNodeFactory.getInstance().createFunction();
funcNew.setFunctionName(getFunctionName())
.setAlias(this.getAlias())
.setTableName(this.getTableName())
.setColumnName(this.getColumnName())
.setDistinct(this.isDistinct())
.setIsNot(this.isNot());
if (getArgs() != null) {
List<Object> argsNew = new ArrayList(getArgs().size());
for (Object arg : getArgs()) {
if (arg instanceof ISelectable) {
argsNew.add(((ISelectable) arg).copy());
} else if (arg instanceof IBindVal) {
argsNew.add((arg));
} else {
argsNew.add(arg);
}
}
funcNew.setArgs(argsNew);
}
return (RT) funcNew;
}
示例6: testDistinct
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testDistinct() throws SqlParserException {
String sql = "SELECT COUNT(DISTINCT ID) FROM TABLE1";
QueryTreeNode qn = query(sql);
TableNode table1 = new TableNode("TABLE1");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
c.setDistinct(true);
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
f.setColumnName("COUNT(DISTINCT ID)");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
qn.build();
QueryTreeNode qnExpected = table1.select(f);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例7: visit
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public void visit(IntervalPrimary node) {
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setColumnName(this.getSqlExprStr(node));
f.setFunctionName(IFunction.BuiltInFunction.INTERVAL);
Expression quantity = node.getQuantity();
MySqlExprVisitor ev = new MySqlExprVisitor();
quantity.accept(ev);
List args = new ArrayList(2);
args.add(ev.getColumnOrValue());
args.add(node.getUnit().toString());
f.setArgs(args);
this.columnOrValue = f;
}
示例8: copy
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public RT copy() {
IFunction funcNew = ASTNodeFactory.getInstance().createFunction();
funcNew.setFunctionName(getFunctionName())
.setAlias(this.getAlias())
.setTableName(this.getTableName())
.setColumnName(this.getColumnName())
.setDistinct(this.isDistinct())
.setIsNot(this.isNot())
.setCorrelateOnFilterId(this.getCorrelateOnFilterId());
funcNew.setNeedDistinctArg(this.isNeedDistinctArg());
if (getArgs() != null) {
List<Object> argsNew = new ArrayList(getArgs().size());
for (Object arg : getArgs()) {
if (arg instanceof ISelectable) {
argsNew.add(((ISelectable) arg).copy());
} else if (arg instanceof IBindVal) {
argsNew.add((((IBindVal) arg).copy()));
} else if (arg instanceof QueryTreeNode) {
argsNew.add((((QueryTreeNode) arg).deepCopy()));
} else {
argsNew.add(arg);
}
}
funcNew.setArgs(argsNew);
}
return (RT) funcNew;
}
示例9: testFunction_to_char
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_to_char() throws Exception {
String sql = "SELECT * FROM TABLE1 T1 WHERE DATE_ADD(ID, INTERVAL 1 SECOND)= '2012-11-11'";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("DATE_ADD");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
List args = new ArrayList();
args.add(c);
args.add("INTERVAL 1 SECOND");
f.setArgs(args);
f.setColumnName("DATE_ADD(ID, INTERVAL 1 SECOND)");
IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
filter.setOperation(OPERATION.EQ);
((IBooleanFilter) filter).setColumn(f);
((IBooleanFilter) filter).setValue("2012-11-11");
QueryTreeNode qnExpected = table1.alias("T1").query(filter);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例10: testFunction_twoArgs
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_twoArgs() throws Exception {
String sql = "SELECT * FROM TABLE1 T1 WHERE IFNULL(STR_TO_DATE(ID, '%d,%m,%y'),1) = '1'";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("STR_TO_DATE");
IFunction f2 = ASTNodeFactory.getInstance().createFunction();
f2.setFunctionName("IFNULL");
f2.setColumnName("IFNULL(STR_TO_DATE(ID, '%d,%m,%y'), 1)");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
List args = new ArrayList();
args.add(c);
args.add("%d,%m,%y");
f.setArgs(args);
f.setColumnName("STR_TO_DATE(id, '%d,%m,%Y')");
args = new ArrayList();
args.add(f);
args.add(1);
f2.setArgs(args);
IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
filter.setOperation(OPERATION.EQ);
((IBooleanFilter) filter).setColumn(f2);
((IBooleanFilter) filter).setValue('1');
QueryTreeNode qnExpected = table1.alias("T1").query(filter);
qnExpected.build();
assertEquals(qn, qnExpected);
}