本文整理汇总了Java中com.taobao.tddl.optimizer.core.expression.IFunction.setFunctionName方法的典型用法代码示例。如果您正苦于以下问题:Java IFunction.setFunctionName方法的具体用法?Java IFunction.setFunctionName怎么用?Java IFunction.setFunctionName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.taobao.tddl.optimizer.core.expression.IFunction
的用法示例。
在下文中一共展示了IFunction.setFunctionName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFunction
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction() throws SqlParserException, QueryException {
String sql = "SELECT COUNT(*) FROM TABLE1 T1 WHERE ID = 1";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("*");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
f.setTableName("TABLE1");
f.setColumnName("COUNT(*)");
QueryTreeNode qnExpected = table1.alias("T1").query("ID=1").select(f);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例2: testFunction1
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction1() throws SqlParserException, QueryException {
String sql = "SELECT COUNT(ID) FROM TABLE1 T1 WHERE ID = 1";
QueryTreeNode qn = query(sql);
TableNode table1 = new TableNode("TABLE1");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
f.setColumnName("COUNT(ID)");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
QueryTreeNode qnExpected = table1.alias("T1").query("ID=1").select(f);
assertEquals(qn, qnExpected);
}
示例3: 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);
}
示例4: 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;
}
示例5: COUNT
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_orderBy加函数() throws Exception {
String sql = "SELECT * FROM TABLE1 WHERE ID=1 ORDER BY COUNT(ID)";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("COUNT");
List args = new ArrayList();
args.add(c);
f.setArgs(args);
f.setColumnName("COUNT(ID)");
QueryTreeNode qnExpected = table1.query("ID=1").orderBy(f, true);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例6: 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;
}
示例7: testFunction_noArgs
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testFunction_noArgs() throws Exception {
String sql = "SELECT * FROM TABLE1 T1 WHERE ID = NOW()";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
IFunction f = ASTNodeFactory.getInstance().createFunction();
f.setFunctionName("NOW");
f.setColumnName("NOW()");
IColumn c = ASTNodeFactory.getInstance().createColumn();
c.setColumnName("ID");
IFilter filter = ASTNodeFactory.getInstance().createBooleanFilter();
filter.setOperation(OPERATION.EQ);
((IBooleanFilter) filter).setColumn(c);
((IBooleanFilter) filter).setValue(f);
QueryTreeNode qnExpected = table1.alias("T1").query(filter);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例8: 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(parent);
expr.getLeftOprand().accept(leftevi);
args.add(leftevi.getColumnOrValue());
MySqlExprVisitor rightevi = new MySqlExprVisitor(parent);
expr.getRightOprand().accept(rightevi);
args.add(rightevi.getColumnOrValue());
func.setArgs(args); // 设置参数
func.setColumnName(getSqlExprStr(expr));
this.columnOrValue = func;
}
示例9: LENGTH
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_函数别名() throws SqlParserException {
String sql = "SELECT T.ID , LENGTH(NAME) AS LEN FROM TABLE1 T WHERE ID=1";
QueryTreeNode qn = query(sql);
qn.build();
IFunction function = ASTNodeFactory.getInstance().createFunction();
function.setColumnName("LENGTH(NAME)");
function.setAlias("LEN");
function.setFunctionName("LENGTH");
QueryTreeNode qnExpected = new TableNode("TABLE1").alias("T").select("T.ID").query("ID=1");
qnExpected.addColumnsSelected(function);
qnExpected.build();
assertEquals(qn, qnExpected);
}
示例10: 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);
}
示例11: 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();
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;
}
示例12: visit
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Override
public void visit(Timestampdiff node) {
boolean argDistinct = isDistinct(node);
IFunction ifunc = ASTNodeFactory.getInstance().createFunction();
ifunc.setFunctionName(node.getFunctionName());
List<Expression> expressions = node.getArguments();
ArrayList<Object> args = new ArrayList<Object>();
args.add(node.getUnit().toString());
if (expressions != null) {
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;
}
示例13: 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);
}
示例14: buildMaxOrMinFunction
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
private IFunction buildMaxOrMinFunction(ISelectable column, boolean isMax) {
IFunction func = ASTNodeFactory.getInstance().createFunction();
func.setFunctionName(isMax ? "MAX" : "MIN");
func.setColumnName(func.getFunctionName() + "(" + column.getColumnName() + ")");
func.getArgs().add(column);
return func;
}
示例15: query
import com.taobao.tddl.optimizer.core.expression.IFunction; //导入方法依赖的package包/类
@Test
public void testQuery_普通链接_函数() throws SqlParserException {
String sql = "SELECT A.ID as AID,A.ID,COUNT(A.ID),COUNT(*) FROM TABLE1 A INNER JOIN TABLE2 B ON A.ID=B.ID AND A.NAME = B.NAME WHERE A.NAME=1";
sql += " GROUP BY AID HAVING AID > 0 ORDER BY A.ID ASC ";
QueryTreeNode qn = query(sql);
qn.build();
TableNode table1 = new TableNode("TABLE1");
TableNode table2 = new TableNode("TABLE2");
QueryTreeNode qnExpected = table1.alias("A")
.join(table2.alias("B"))
.addJoinKeys("A.ID", "B.ID")
.addJoinKeys("A.NAME", "B.NAME")
.query("A.NAME=1")
.select("A.ID AS AID,A.ID")
.groupBy("AID")
.having("AID > 0")
.orderBy("A.ID", true);
IFunction function1 = ASTNodeFactory.getInstance().createFunction();
function1.setColumnName("COUNT(A.ID)");
function1.setFunctionName("COUNT");
IFunction function2 = ASTNodeFactory.getInstance().createFunction();
function2.setColumnName("COUNT(*)");
function2.setFunctionName("COUNT");
qnExpected.addColumnsSelected(function1);
qnExpected.addColumnsSelected(function2);
qnExpected.build();
assertEquals(qn, qnExpected);
}