mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql parser.
This commit is contained in:
@@ -73,6 +73,9 @@ public class SQLBlockStatement extends SQLStatementImpl {
|
||||
}
|
||||
|
||||
public void setException(SQLStatement exception) {
|
||||
if (exception != null) {
|
||||
exception.setParent(this);
|
||||
}
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
|
||||
+15
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
|
||||
+3
-1
@@ -42,12 +42,14 @@ public class MySqlCursorDeclareStatement extends MySqlStatementImpl{
|
||||
}
|
||||
|
||||
public void setSelect(SQLSelectStatement select) {
|
||||
if (select != null) {
|
||||
select.setParent(this);
|
||||
}
|
||||
this.select = select;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
// TODO Auto-generated method stub
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, select);
|
||||
}
|
||||
|
||||
@@ -3619,6 +3619,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
SQLIfStatement.ElseIf elseIf = new SQLIfStatement.ElseIf();
|
||||
|
||||
elseIf.setCondition(this.exprParser.expr());
|
||||
elseIf.setParent(stmt);
|
||||
|
||||
accept(Token.THEN);
|
||||
this.parseStatementList(elseIf.getStatements(), -1, elseIf);
|
||||
|
||||
@@ -178,7 +178,9 @@ public class OdpsSelectParser extends SQLSelectParser {
|
||||
|
||||
protected SQLTableSource parseLateralView(SQLTableSource tableSource) {
|
||||
accept(Token.VIEW);
|
||||
tableSource.setAlias(null);
|
||||
if ("LATERAL".equalsIgnoreCase(tableSource.getAlias())) {
|
||||
tableSource.setAlias(null);
|
||||
}
|
||||
OdpsLateralViewTableSource lateralViewTabSrc = new OdpsLateralViewTableSource();
|
||||
lateralViewTabSrc.setTableSource(tableSource);
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ public class OracleForStatement extends OracleStatementImpl {
|
||||
}
|
||||
|
||||
public void setRange(SQLExpr range) {
|
||||
if (range != null) {
|
||||
range.setParent(this);
|
||||
}
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
|
||||
@@ -740,6 +740,13 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLCreateFunctionStatement parseCreateFunction() {
|
||||
accept(Token.CREATE);
|
||||
SQLCreateFunctionStatement stmt = (SQLCreateFunctionStatement) parseFunction();
|
||||
stmt.setCreate(true);
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseFunction() {
|
||||
SQLCreateFunctionStatement stmt = new SQLCreateFunctionStatement();
|
||||
stmt.setDbType(dbType);
|
||||
@@ -893,6 +900,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
SQLIfStatement.ElseIf elseIf = new SQLIfStatement.ElseIf();
|
||||
|
||||
elseIf.setCondition(this.exprParser.expr());
|
||||
elseIf.setParent(stmt);
|
||||
|
||||
accept(Token.THEN);
|
||||
this.parseStatementList(elseIf.getStatements(), -1, stmt);
|
||||
@@ -903,6 +911,8 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() == Token.ELSE) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
|
||||
SQLIfStatement.Else elseItem = new SQLIfStatement.Else();
|
||||
this.parseStatementList(elseItem.getStatements(), -1, elseItem);
|
||||
stmt.setElseItem(elseItem);
|
||||
|
||||
@@ -1865,7 +1865,10 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
}
|
||||
x.getIndex().accept(this);
|
||||
print0(ucase ? " IN " : " in ");
|
||||
x.getRange().accept(this);
|
||||
|
||||
SQLExpr range = x.getRange();
|
||||
range.accept(this);
|
||||
|
||||
if (!all) {
|
||||
println();
|
||||
print0(ucase ? "LOOP" : "loop");
|
||||
|
||||
@@ -1840,6 +1840,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
SQLCreateProcedureStatement stmt = parseCreateProcedure();
|
||||
stmt.setCreate(true);
|
||||
return stmt;
|
||||
} else if (token == Token.FUNCTION) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
SQLStatement stmt = this.parseCreateFunction();
|
||||
return stmt;
|
||||
} else if (identifierEquals("BITMAP")) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
return parseCreateIndex(true);
|
||||
@@ -1851,6 +1855,10 @@ public class SQLStatementParser extends SQLParser {
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
}
|
||||
|
||||
public SQLCreateFunctionStatement parseCreateFunction() {
|
||||
throw new ParserException("TODO " + lexer.token());
|
||||
}
|
||||
|
||||
public SQLStatement parseCreateMaterializedView() {
|
||||
accept(Token.CREATE);
|
||||
acceptIdentifier("MATERIALIZED");
|
||||
|
||||
@@ -36,12 +36,22 @@ import java.util.concurrent.ConcurrentSkipListMap;
|
||||
* Created by wenshao on 03/06/2017.
|
||||
*/
|
||||
public class SchemaRepository {
|
||||
private String name;
|
||||
|
||||
private final Map<String, SchemaObject> objects = new ConcurrentSkipListMap<String, SchemaObject>();
|
||||
|
||||
private final Map<String, SchemaObject> functions = new ConcurrentSkipListMap<String, SchemaObject>();
|
||||
|
||||
private final SchemaVisitor visitor = new SchemaVisitor();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SchemaObject findTable(String tableName) {
|
||||
String lowerName = tableName.toLowerCase();
|
||||
SchemaObject object = objects.get(lowerName);
|
||||
@@ -144,6 +154,16 @@ public class SchemaRepository {
|
||||
}
|
||||
return tableObject;
|
||||
}
|
||||
|
||||
if (expr instanceof SQLPropertyExpr) {
|
||||
String tableName = ((SQLPropertyExpr) expr).getName();
|
||||
|
||||
tableObject = findTable(tableName);
|
||||
if (tableObject != null) {
|
||||
exprTableSource.setSchemaObject(tableObject);
|
||||
}
|
||||
return tableObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -222,6 +242,16 @@ public class SchemaRepository {
|
||||
if (tableSource instanceof SQLExprTableSource) {
|
||||
return findTable(tableSource, tableSource.computeAlias());
|
||||
}
|
||||
|
||||
if (tableSource instanceof SQLJoinTableSource) {
|
||||
SQLJoinTableSource join = (SQLJoinTableSource) tableSource;
|
||||
|
||||
SchemaObject table = findTable(join.getLeft(), expr);
|
||||
if (table == null) {
|
||||
table = findTable(join.getRight(), expr);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributes;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreatePackageStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -263,21 +264,55 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
}
|
||||
|
||||
private static int paramCount(SQLExpr x) {
|
||||
if (x instanceof SQLMethodInvokeExpr) {
|
||||
List<SQLExpr> params = ((SQLMethodInvokeExpr) x).getParameters();
|
||||
int paramCount = 1;
|
||||
for (SQLExpr param : params) {
|
||||
paramCount += paramCount(param);
|
||||
}
|
||||
return paramCount;
|
||||
}
|
||||
|
||||
if (x instanceof SQLAggregateExpr) {
|
||||
List<SQLExpr> params = ((SQLAggregateExpr) x).getArguments();
|
||||
int paramCount = 1;
|
||||
for (SQLExpr param : params) {
|
||||
paramCount += paramCount(param);
|
||||
}
|
||||
return paramCount;
|
||||
}
|
||||
|
||||
if (x instanceof SQLBinaryOpExpr) {
|
||||
return paramCount(((SQLBinaryOpExpr) x).getLeft())
|
||||
+ paramCount(((SQLBinaryOpExpr) x).getRight());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected void printSelectList(List<SQLSelectItem> selectList) {
|
||||
incrementIndent();
|
||||
for (int i = 0, lineItemCount = 0, size = selectList.size()
|
||||
; i < size; ++i, ++lineItemCount) {
|
||||
SQLSelectItem selectItem = selectList.get(i);
|
||||
SQLExpr selectItemExpr = selectItem.getExpr();
|
||||
|
||||
int paramCount = paramCount(selectItemExpr);
|
||||
if (selectItemExpr instanceof SQLMethodInvokeExpr
|
||||
|| selectItemExpr instanceof SQLAggregateExpr
|
||||
|| selectItemExpr instanceof SQLBinaryOpExpr) {
|
||||
lineItemCount += (paramCount - 1);
|
||||
}
|
||||
|
||||
if (i != 0) {
|
||||
SQLSelectItem preSelectItem = selectList.get(i - 1);
|
||||
if (preSelectItem.getAfterCommentsDirect() != null) {
|
||||
lineItemCount = 0;
|
||||
println();
|
||||
} else if (selectItemExpr instanceof SQLMethodInvokeExpr) {
|
||||
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) selectItemExpr;
|
||||
int paramCount = methodInvokeExpr.getParameters().size();
|
||||
lineItemCount += paramCount;
|
||||
} else if (selectItemExpr instanceof SQLMethodInvokeExpr
|
||||
|| selectItemExpr instanceof SQLAggregateExpr
|
||||
|| selectItemExpr instanceof SQLBinaryOpExpr) {
|
||||
if (lineItemCount >= selectListNumberOfLine) {
|
||||
lineItemCount = paramCount;
|
||||
println();
|
||||
@@ -1198,19 +1233,20 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
if (parent instanceof SQLStatement) {
|
||||
if (parent instanceof ValuesClause) {
|
||||
println();
|
||||
print('(');
|
||||
x.getSubQuery().accept(this);
|
||||
print(')');
|
||||
println();
|
||||
} else if (parent instanceof SQLStatement
|
||||
&& !(parent instanceof OracleForStatement)) {
|
||||
incrementIndent();
|
||||
|
||||
println();
|
||||
x.getSubQuery().accept(this);
|
||||
|
||||
decrementIndent();
|
||||
} else if (parent instanceof ValuesClause) {
|
||||
println();
|
||||
print('(');
|
||||
x.getSubQuery().accept(this);
|
||||
print(')');
|
||||
println();
|
||||
} else if (parent instanceof SQLOpenStatement) {
|
||||
x.getSubQuery().accept(this);
|
||||
} else {
|
||||
|
||||
@@ -22,11 +22,11 @@ public class BuilderSelectTest extends TestCase {
|
||||
|
||||
String sql = builder.toString();
|
||||
System.out.println(sql);
|
||||
Assert.assertEquals("SELECT f1, f2, f3 AS F3, COUNT(*) AS cnt" //
|
||||
+ "\nFROM mytable"//
|
||||
+ "\nWHERE f1 > 0"//
|
||||
+ "\nGROUP BY f1"//
|
||||
+ "\nHAVING COUNT(*) > 1"//
|
||||
+ "\nORDER BY f1, f2 DESC", sql);
|
||||
Assert.assertEquals("SELECT f1, f2, f3 AS F3, COUNT(*) AS cnt\n" +
|
||||
"FROM mytable\n" +
|
||||
"WHERE f1 > 0\n" +
|
||||
"GROUP BY f1\n" +
|
||||
"HAVING COUNT(*) > 1\n" +
|
||||
"ORDER BY f1, f2 DESC", sql);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,8 @@ public class BitFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT b + 0, BIN(b + 0), OCT(b + 0)\n" +
|
||||
Assert.assertEquals("SELECT b + 0, BIN(b + 0)\n" +
|
||||
"\t, OCT(b + 0)\n" +
|
||||
"\t, HEX(b + 0)\n" +
|
||||
"FROM t;", text);
|
||||
}
|
||||
|
||||
+10
-5
@@ -59,7 +59,8 @@ public class ComparisonFunctionsAndOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;", text);
|
||||
Assert.assertEquals("SELECT 1 <=> 1, NULL <=> NULL\n" +
|
||||
"\t, 1 <=> NULL;", text);
|
||||
}
|
||||
|
||||
public void test_3() throws Exception {
|
||||
@@ -70,7 +71,8 @@ public class ComparisonFunctionsAndOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 = 1, NULL = NULL, 1 = NULL;", text);
|
||||
Assert.assertEquals("SELECT 1 = 1, NULL = NULL\n" +
|
||||
"\t, 1 = NULL;", text);
|
||||
}
|
||||
|
||||
public void test_4() throws Exception {
|
||||
@@ -136,7 +138,8 @@ public class ComparisonFunctionsAndOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
assertEquals("SELECT 1 IS true, 0 IS false, NULL IS UNKNOWN", text);
|
||||
assertEquals("SELECT 1 IS true, 0 IS false\n" +
|
||||
"\t, NULL IS UNKNOWN", text);
|
||||
}
|
||||
|
||||
public void test_10() throws Exception {
|
||||
@@ -147,7 +150,8 @@ public class ComparisonFunctionsAndOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 IS NOT UNKNOWN, 0 IS NOT UNKNOWN, NULL IS NOT UNKNOWN", text);
|
||||
Assert.assertEquals("SELECT 1 IS NOT UNKNOWN, 0 IS NOT UNKNOWN\n" +
|
||||
"\t, NULL IS NOT UNKNOWN", text);
|
||||
}
|
||||
|
||||
public void test_11() throws Exception {
|
||||
@@ -158,7 +162,8 @@ public class ComparisonFunctionsAndOperatorsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 1 IS NULL, 0 IS NULL, NULL IS NULL", text);
|
||||
Assert.assertEquals("SELECT 1 IS NULL, 0 IS NULL\n" +
|
||||
"\t, NULL IS NULL", text);
|
||||
}
|
||||
|
||||
public void test_12() throws Exception {
|
||||
|
||||
@@ -180,7 +180,8 @@ public class StringComparisonFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT STRCMP(@s1, @s2), STRCMP(@s3, @s4);", text);
|
||||
Assert.assertEquals("SELECT STRCMP(@s1, @s2)\n" +
|
||||
"\t, STRCMP(@s3, @s4);", text);
|
||||
}
|
||||
|
||||
public void test_14() throws Exception {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT ASCII('2');", text);
|
||||
assertEquals("SELECT ASCII('2');", text);
|
||||
}
|
||||
|
||||
public void test_1() throws Exception {
|
||||
@@ -48,7 +48,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT ASCII(2);", text);
|
||||
assertEquals("SELECT ASCII(2);", text);
|
||||
}
|
||||
|
||||
public void test_2() throws Exception {
|
||||
@@ -59,7 +59,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT BIN(12);", text);
|
||||
assertEquals("SELECT BIN(12);", text);
|
||||
}
|
||||
|
||||
public void test_3() throws Exception {
|
||||
@@ -70,7 +70,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT BIT_LENGTH('text');", text);
|
||||
assertEquals("SELECT BIT_LENGTH('text');", text);
|
||||
}
|
||||
|
||||
public void test_4() throws Exception {
|
||||
@@ -81,7 +81,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CHAR(77, 121, 83, 81, '76');", text);
|
||||
assertEquals("SELECT CHAR(77, 121, 83, 81, '76');", text);
|
||||
}
|
||||
|
||||
public void test_5() throws Exception {
|
||||
@@ -92,7 +92,8 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT HEX(CHAR(1, 0)), HEX(CHAR(256));", text);
|
||||
assertEquals("SELECT HEX(CHAR(1, 0))\n" +
|
||||
"\t, HEX(CHAR(256));", text);
|
||||
}
|
||||
|
||||
public void test_6() throws Exception {
|
||||
@@ -103,7 +104,8 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT HEX(CHAR(1, 0, 0)), HEX(CHAR(256 * 256));", text);
|
||||
assertEquals("SELECT HEX(CHAR(1, 0, 0))\n" +
|
||||
"\t, HEX(CHAR(256 * 256));", text);
|
||||
}
|
||||
|
||||
public void test_7() throws Exception {
|
||||
@@ -114,7 +116,8 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CHARSET(CHAR(0x65)), CHARSET(CHAR(0x65 USING utf8))", text);
|
||||
assertEquals("SELECT CHARSET(CHAR(0x65))\n" +
|
||||
"\t, CHARSET(CHAR(0x65 USING utf8))", text);
|
||||
}
|
||||
|
||||
public void test_8() throws Exception {
|
||||
@@ -125,7 +128,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CONCAT(CAST(int_col AS CHAR), char_col)", text);
|
||||
assertEquals("SELECT CONCAT(CAST(int_col AS CHAR), char_col)", text);
|
||||
}
|
||||
|
||||
public void test_9() throws Exception {
|
||||
@@ -136,7 +139,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CONCAT('My', 'S', 'QL')", text);
|
||||
assertEquals("SELECT CONCAT('My', 'S', 'QL')", text);
|
||||
}
|
||||
|
||||
public void test_10() throws Exception {
|
||||
@@ -147,7 +150,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CONCAT_WS(',', 'First name', 'Second name', 'Last Name');", text);
|
||||
assertEquals("SELECT CONCAT_WS(',', 'First name', 'Second name', 'Last Name');", text);
|
||||
}
|
||||
|
||||
public void test_11() throws Exception {
|
||||
@@ -158,7 +161,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT CONCAT_WS(',', 'First name', NULL, 'Last Name');", text);
|
||||
assertEquals("SELECT CONCAT_WS(',', 'First name', NULL, 'Last Name');", text);
|
||||
}
|
||||
|
||||
public void test_12() throws Exception {
|
||||
@@ -169,7 +172,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT ELT(1, 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
assertEquals("SELECT ELT(1, 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
}
|
||||
|
||||
public void test_13() throws Exception {
|
||||
@@ -180,7 +183,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT ELT(4, 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
assertEquals("SELECT ELT(4, 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
}
|
||||
|
||||
public void test_14() throws Exception {
|
||||
@@ -191,7 +194,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT EXPORT_SET(5, 'Y', 'N', ',', 4);", text);
|
||||
assertEquals("SELECT EXPORT_SET(5, 'Y', 'N', ',', 4);", text);
|
||||
}
|
||||
|
||||
public void test_15() throws Exception {
|
||||
@@ -202,7 +205,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT EXPORT_SET(6, '1', '0', ',', 10);", text);
|
||||
assertEquals("SELECT EXPORT_SET(6, '1', '0', ',', 10);", text);
|
||||
}
|
||||
|
||||
public void test_16() throws Exception {
|
||||
@@ -213,7 +216,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
assertEquals("SELECT FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');", text);
|
||||
}
|
||||
|
||||
public void test_17() throws Exception {
|
||||
@@ -224,7 +227,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT FIND_IN_SET('b', 'a,b,c,d');", text);
|
||||
assertEquals("SELECT FIND_IN_SET('b', 'a,b,c,d');", text);
|
||||
}
|
||||
|
||||
public void test_18() throws Exception {
|
||||
@@ -235,7 +238,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT FORMAT(12332.123456, 4);", text);
|
||||
assertEquals("SELECT FORMAT(12332.123456, 4);", text);
|
||||
}
|
||||
|
||||
public void test_19() throws Exception {
|
||||
@@ -246,7 +249,8 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 0x616263, HEX('abc'), UNHEX(HEX('abc'));", text);
|
||||
assertEquals("SELECT 0x616263, HEX('abc')\n" +
|
||||
"\t, UNHEX(HEX('abc'));", text);
|
||||
}
|
||||
|
||||
public void test_20() throws Exception {
|
||||
@@ -257,7 +261,8 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT HEX(255), CONV(HEX(255), 16, 10);", text);
|
||||
assertEquals("SELECT HEX(255)\n" +
|
||||
"\t, CONV(HEX(255), 16, 10);", text);
|
||||
}
|
||||
|
||||
public void test_21() throws Exception {
|
||||
@@ -268,7 +273,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT INSERT('Quadratic', 3, 4, 'What');", text);
|
||||
assertEquals("SELECT INSERT('Quadratic', 3, 4, 'What');", text);
|
||||
}
|
||||
|
||||
public void test_22() throws Exception {
|
||||
@@ -279,7 +284,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT INSERT('Quadratic', -1, 4, 'What');", text);
|
||||
assertEquals("SELECT INSERT('Quadratic', -1, 4, 'What');", text);
|
||||
}
|
||||
|
||||
public void test_23() throws Exception {
|
||||
@@ -290,7 +295,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT INSTR('foobarbar', 'bar');", text);
|
||||
assertEquals("SELECT INSTR('foobarbar', 'bar');", text);
|
||||
}
|
||||
|
||||
public void test_24() throws Exception {
|
||||
@@ -301,7 +306,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LEFT('foobarbar', 5);", text);
|
||||
assertEquals("SELECT LEFT('foobarbar', 5);", text);
|
||||
}
|
||||
|
||||
public void test_25() throws Exception {
|
||||
@@ -312,7 +317,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LENGTH('text');", text);
|
||||
assertEquals("SELECT LENGTH('text');", text);
|
||||
}
|
||||
|
||||
public void test_26() throws Exception {
|
||||
@@ -323,7 +328,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("UPDATE t\nSET blob_col = LOAD_FILE('/tmp/picture')\nWHERE id = 1;", text);
|
||||
assertEquals("UPDATE t\nSET blob_col = LOAD_FILE('/tmp/picture')\nWHERE id = 1;", text);
|
||||
}
|
||||
|
||||
public void test_27() throws Exception {
|
||||
@@ -334,7 +339,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LOCATE('bar', 'foobarbar');", text);
|
||||
assertEquals("SELECT LOCATE('bar', 'foobarbar');", text);
|
||||
}
|
||||
|
||||
public void test_28() throws Exception {
|
||||
@@ -345,7 +350,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LOWER('QUADRATICALLY');", text);
|
||||
assertEquals("SELECT LOWER('QUADRATICALLY');", text);
|
||||
}
|
||||
|
||||
public void test_29() throws Exception {
|
||||
@@ -356,7 +361,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LPAD('hi', 4, '??');", text);
|
||||
assertEquals("SELECT LPAD('hi', 4, '??');", text);
|
||||
}
|
||||
|
||||
public void test_30() throws Exception {
|
||||
@@ -367,7 +372,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT LTRIM(' barbar')", text);
|
||||
assertEquals("SELECT LTRIM(' barbar')", text);
|
||||
}
|
||||
|
||||
public void test_31() throws Exception {
|
||||
@@ -378,7 +383,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT MAKE_SET(1, 'a', 'b', 'c')", text);
|
||||
assertEquals("SELECT MAKE_SET(1, 'a', 'b', 'c')", text);
|
||||
}
|
||||
|
||||
public void test_32() throws Exception {
|
||||
@@ -389,7 +394,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT MAKE_SET(1 | 4, 'hello', 'nice', 'world')", text);
|
||||
assertEquals("SELECT MAKE_SET(1 | 4, 'hello', 'nice', 'world')", text);
|
||||
}
|
||||
|
||||
public void test_33() throws Exception {
|
||||
@@ -400,7 +405,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT MAKE_SET(1 | 4, 'hello', 'nice', NULL, 'world')", text);
|
||||
assertEquals("SELECT MAKE_SET(1 | 4, 'hello', 'nice', NULL, 'world')", text);
|
||||
}
|
||||
|
||||
public void test_34() throws Exception {
|
||||
@@ -411,7 +416,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT ORD('2')", text);
|
||||
assertEquals("SELECT ORD('2')", text);
|
||||
}
|
||||
|
||||
public void test_35() throws Exception {
|
||||
@@ -422,7 +427,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT QUOTE('Don''t!')", text);
|
||||
assertEquals("SELECT QUOTE('Don''t!')", text);
|
||||
}
|
||||
|
||||
public void test_36() throws Exception {
|
||||
@@ -433,7 +438,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT REPEAT('MySQL', 3)", text);
|
||||
assertEquals("SELECT REPEAT('MySQL', 3)", text);
|
||||
}
|
||||
|
||||
public void test_37() throws Exception {
|
||||
@@ -444,7 +449,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT REVERSE('abc')", text);
|
||||
assertEquals("SELECT REVERSE('abc')", text);
|
||||
}
|
||||
|
||||
public void test_38() throws Exception {
|
||||
@@ -455,7 +460,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT RIGHT('foobarbar', 4)", text);
|
||||
assertEquals("SELECT RIGHT('foobarbar', 4)", text);
|
||||
}
|
||||
|
||||
public void test_39() throws Exception {
|
||||
@@ -466,7 +471,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT RPAD('hi', 5, '?')", text);
|
||||
assertEquals("SELECT RPAD('hi', 5, '?')", text);
|
||||
}
|
||||
|
||||
public void test_40() throws Exception {
|
||||
@@ -477,7 +482,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT RTRIM('barbar ')", text);
|
||||
assertEquals("SELECT RTRIM('barbar ')", text);
|
||||
}
|
||||
|
||||
public void test_41() throws Exception {
|
||||
@@ -488,7 +493,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SOUNDEX('Hello')", text);
|
||||
assertEquals("SELECT SOUNDEX('Hello')", text);
|
||||
}
|
||||
|
||||
public void test_42() throws Exception {
|
||||
@@ -499,7 +504,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SPACE(6)", text);
|
||||
assertEquals("SELECT SPACE(6)", text);
|
||||
}
|
||||
|
||||
public void test_43() throws Exception {
|
||||
@@ -510,7 +515,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SUBSTRING('Quadratically', 5)", text);
|
||||
assertEquals("SELECT SUBSTRING('Quadratically', 5)", text);
|
||||
}
|
||||
|
||||
public void test_44() throws Exception {
|
||||
@@ -521,7 +526,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SUBSTRING('Sakila', -4, 2)", text);
|
||||
assertEquals("SELECT SUBSTRING('Sakila', -4, 2)", text);
|
||||
}
|
||||
|
||||
public void test_45() throws Exception {
|
||||
@@ -532,7 +537,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SUBSTRING('foobarbar', 4)", text);
|
||||
assertEquals("SELECT SUBSTRING('foobarbar', 4)", text);
|
||||
}
|
||||
|
||||
public void test_46() throws Exception {
|
||||
@@ -543,7 +548,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SUBSTRING('Quadratically', 5, 6)", text);
|
||||
assertEquals("SELECT SUBSTRING('Quadratically', 5, 6)", text);
|
||||
}
|
||||
|
||||
public void test_47() throws Exception {
|
||||
@@ -554,7 +559,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2)", text);
|
||||
assertEquals("SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2)", text);
|
||||
}
|
||||
|
||||
public void test_48() throws Exception {
|
||||
@@ -565,7 +570,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT TRIM(' bar ')", text);
|
||||
assertEquals("SELECT TRIM(' bar ')", text);
|
||||
}
|
||||
|
||||
public void test_49() throws Exception {
|
||||
@@ -576,7 +581,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx')", text);
|
||||
assertEquals("SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx')", text);
|
||||
}
|
||||
|
||||
public void test_50() throws Exception {
|
||||
@@ -587,7 +592,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');", text);
|
||||
assertEquals("SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');", text);
|
||||
}
|
||||
|
||||
public void test_51() throws Exception {
|
||||
@@ -598,7 +603,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');", text);
|
||||
assertEquals("SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');", text);
|
||||
}
|
||||
|
||||
public void test_52() throws Exception {
|
||||
@@ -609,7 +614,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT UNHEX('4D7953514C');", text);
|
||||
assertEquals("SELECT UNHEX('4D7953514C');", text);
|
||||
}
|
||||
|
||||
public void test_53() throws Exception {
|
||||
@@ -620,7 +625,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT 0x4D7953514C;", text);
|
||||
assertEquals("SELECT 0x4D7953514C;", text);
|
||||
}
|
||||
|
||||
public void test_54() throws Exception {
|
||||
@@ -631,7 +636,7 @@ public class StringFunctionsTest extends TestCase {
|
||||
|
||||
String text = output(stmtList);
|
||||
|
||||
Assert.assertEquals("SELECT UPPER('Hej');", text);
|
||||
assertEquals("SELECT UPPER('Hej');", text);
|
||||
}
|
||||
|
||||
private String output(List<SQLStatement> stmtList) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MySqlCreateProcedureTest5 extends MysqlTest {
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement statemen = statementList.get(0);
|
||||
// print(statementList);
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
statemen.accept(visitor);
|
||||
@@ -58,14 +58,14 @@ public class MySqlCreateProcedureTest5 extends MysqlTest {
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(1, visitor.getTables().size());
|
||||
Assert.assertEquals(2, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
assertEquals(1, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
|
||||
assertTrue(visitor.getTables().containsKey(new TableStat.Name("test")));
|
||||
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "id")));
|
||||
Assert.assertTrue(visitor.getColumns().contains(new Column("test", "age")));
|
||||
assertTrue(visitor.getColumns().contains(new Column("test", "id")));
|
||||
// assertTrue(visitor.getColumns().contains(new Column("test", "age")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-2
@@ -32,8 +32,11 @@ public class MySqlParameterizedOutputVisitorTest_38 extends TestCase {
|
||||
visitor.setParameterizedMergeInList(true);
|
||||
// visitor.setParameters(parameters);
|
||||
visitor.setExportTables(true);
|
||||
visitor.setPrettyFormat(false);
|
||||
visitor.setPrettyFormat(true);
|
||||
statement.accept(visitor);
|
||||
assertEquals("SELECT lower(hex(file_md5)) AS file_md5, lower(hex(thumb)) AS thumb, st FROM t_f_p_thumb WHERE file_md5 = ?", out.toString());
|
||||
assertEquals("SELECT lower(hex(file_md5)) AS file_md5\n" +
|
||||
"\t, lower(hex(thumb)) AS thumb, st\n" +
|
||||
"FROM t_f_p_thumb\n" +
|
||||
"WHERE file_md5 = ?", out.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ public class MySqlSelectTest_33 extends MysqlTest {
|
||||
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("SELECT COUNT() AS count, DATE_FORMAT(DATE(reg_time), '%Y-%m-%d') AS date, HOUR(reg_time) DIV 2 AS intervalTime\n" +
|
||||
Assert.assertEquals("SELECT COUNT() AS count, DATE_FORMAT(DATE(reg_time), '%Y-%m-%d') AS date\n" +
|
||||
"\t, HOUR(reg_time) DIV 2 AS intervalTime\n" +
|
||||
"FROM USER_RECOMMEND_INFO\n" +
|
||||
"WHERE 1 = 1\n" +
|
||||
"\tAND reg_time >= '2016-12-01 00:00:00'\n" +
|
||||
@@ -68,7 +69,8 @@ public class MySqlSelectTest_33 extends MysqlTest {
|
||||
}
|
||||
{
|
||||
String output = SQLUtils.toMySqlString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
|
||||
Assert.assertEquals("select count() as count, DATE_FORMAT(DATE(reg_time), '%Y-%m-%d') as date, HOUR(reg_time) div 2 as intervalTime\n" +
|
||||
Assert.assertEquals("select count() as count, DATE_FORMAT(DATE(reg_time), '%Y-%m-%d') as date\n" +
|
||||
"\t, HOUR(reg_time) div 2 as intervalTime\n" +
|
||||
"from USER_RECOMMEND_INFO\n" +
|
||||
"where 1 = 1\n" +
|
||||
"\tand reg_time >= '2016-12-01 00:00:00'\n" +
|
||||
|
||||
+6
-3
@@ -59,7 +59,8 @@ public class MySqlSelectTest_44_with_cte extends MysqlTest {
|
||||
Assert.assertEquals("WITH RECURSIVE cte AS (\n" +
|
||||
"\t\tSELECT 1 AS n, 1 AS p, -1 AS q\n" +
|
||||
"\t\tUNION ALL\n" +
|
||||
"\t\tSELECT n + 1, q * 2, p * 2\n" +
|
||||
"\t\tSELECT n + 1, q * 2\n" +
|
||||
"\t\t\t, p * 2\n" +
|
||||
"\t\tFROM cte\n" +
|
||||
"\t\tWHERE n < 5\n" +
|
||||
"\t)\n" +
|
||||
@@ -72,7 +73,8 @@ public class MySqlSelectTest_44_with_cte extends MysqlTest {
|
||||
Assert.assertEquals("with recursive cte as (\n" +
|
||||
"\t\tselect 1 as n, 1 as p, -1 as q\n" +
|
||||
"\t\tunion all\n" +
|
||||
"\t\tselect n + 1, q * 2, p * 2\n" +
|
||||
"\t\tselect n + 1, q * 2\n" +
|
||||
"\t\t\t, p * 2\n" +
|
||||
"\t\tfrom cte\n" +
|
||||
"\t\twhere n < 5\n" +
|
||||
"\t)\n" +
|
||||
@@ -86,7 +88,8 @@ public class MySqlSelectTest_44_with_cte extends MysqlTest {
|
||||
Assert.assertEquals("WITH RECURSIVE cte AS (\n" +
|
||||
"\t\tSELECT ? AS n, ? AS p, ? AS q\n" +
|
||||
"\t\tUNION ALL\n" +
|
||||
"\t\tSELECT n + ?, q * ?, p * ?\n" +
|
||||
"\t\tSELECT n + ?, q * ?\n" +
|
||||
"\t\t\t, p * ?\n" +
|
||||
"\t\tFROM cte\n" +
|
||||
"\t\tWHERE n < ?\n" +
|
||||
"\t)\n" +
|
||||
|
||||
@@ -55,13 +55,18 @@ public class OdpsSelectTest22 extends TestCase {
|
||||
"where UT.ad_clk > 0 or CLK.clk > 0\n" +
|
||||
") A\n" +
|
||||
"group by bucket_id;";//
|
||||
assertEquals("SELECT bucket_id, SUM(pv) AS pv, SUM(clk) AS clk, SUM(clk) / (SUM(pv) + 1E-10) AS ctr, SUM(ut_ad_clk) AS ut_ad_clk\n" +
|
||||
"\t, SUM(ad_clk) AS ad_clk, SUM(cost) AS cost, SUM(cost) * 1000 / (SUM(pv) + 1E-10) / 100 AS rpm\n" +
|
||||
assertEquals("SELECT bucket_id, SUM(pv) AS pv, SUM(clk) AS clk\n" +
|
||||
"\t, SUM(clk) / (SUM(pv) + 1E-10) AS ctr\n" +
|
||||
"\t, SUM(ut_ad_clk) AS ut_ad_clk, SUM(ad_clk) AS ad_clk\n" +
|
||||
"\t, SUM(cost) AS cost\n" +
|
||||
"\t, SUM(cost) * 1000 / (SUM(pv) + 1E-10) / 100 AS rpm\n" +
|
||||
"FROM (\n" +
|
||||
"\tSELECT bucket_id, UT.pv AS pv, UT.clk AS clk, UT.ad_clk AS ut_ad_clk, CLK.clk AS ad_clk\n" +
|
||||
"\t\t, CLK.cost AS cost\n" +
|
||||
"\tFROM (\n" +
|
||||
"\t\tSELECT item_id, pv_id, SUM(pv) AS pv, SUM(clk) AS clk, SUM(IF(str_to_map(args, ',', '=')['sid'] IS NOT NULL, clk, 0)) AS ad_clk\n" +
|
||||
"\t\tSELECT item_id, pv_id, SUM(pv) AS pv\n" +
|
||||
"\t\t\t, SUM(clk) AS clk\n" +
|
||||
"\t\t\t, SUM(IF(str_to_map(args, ',', '=')['sid'] IS NOT NULL, clk, 0)) AS ad_clk\n" +
|
||||
"\t\t\t, str_to_map(args, ',', '=')['sid'] AS ad_session, split_part(str_to_map(args, ',', '=')['scm'], '.', 2) AS bucket_id\n" +
|
||||
"\t\tFROM alimama_algo.fund_mlr_n_chicago_user_track_distinct_shark\n" +
|
||||
"\t\tWHERE ds = 20170627\n" +
|
||||
@@ -73,7 +78,8 @@ public class OdpsSelectTest22 extends TestCase {
|
||||
"\t\t\tsplit_part(str_to_map(args, ',', '=')['scm'], '.', 2)\n" +
|
||||
"\t) UT\n" +
|
||||
"\tLEFT OUTER JOIN (\n" +
|
||||
"\t\tSELECT pv_id AS ad_session, item_it AS item_id, SUM(click_price) AS cost, COUNT(*) AS clk\n" +
|
||||
"\t\tSELECT pv_id AS ad_session, item_it AS item_id, SUM(click_price) AS cost\n" +
|
||||
"\t\t\t, COUNT(*) AS clk\n" +
|
||||
"\t\tFROM alimama_algo.fund_mlr_n_chicago_offline_click\n" +
|
||||
"\t\tWHERE ds = 20170627\n" +
|
||||
"\t\t\tAND hh = 0\n" +
|
||||
@@ -88,13 +94,18 @@ public class OdpsSelectTest22 extends TestCase {
|
||||
") A\n" +
|
||||
"GROUP BY bucket_id;", SQLUtils.formatOdps(sql));
|
||||
|
||||
assertEquals("select bucket_id, sum(pv) as pv, sum(clk) as clk, sum(clk) / (sum(pv) + 1E-10) as ctr, sum(ut_ad_clk) as ut_ad_clk\n" +
|
||||
"\t, sum(ad_clk) as ad_clk, sum(cost) as cost, sum(cost) * 1000 / (sum(pv) + 1E-10) / 100 as rpm\n" +
|
||||
assertEquals("select bucket_id, sum(pv) as pv, sum(clk) as clk\n" +
|
||||
"\t, sum(clk) / (sum(pv) + 1E-10) as ctr\n" +
|
||||
"\t, sum(ut_ad_clk) as ut_ad_clk, sum(ad_clk) as ad_clk\n" +
|
||||
"\t, sum(cost) as cost\n" +
|
||||
"\t, sum(cost) * 1000 / (sum(pv) + 1E-10) / 100 as rpm\n" +
|
||||
"from (\n" +
|
||||
"\tselect bucket_id, UT.pv as pv, UT.clk as clk, UT.ad_clk as ut_ad_clk, CLK.clk as ad_clk\n" +
|
||||
"\t\t, CLK.cost as cost\n" +
|
||||
"\tfrom (\n" +
|
||||
"\t\tselect item_id, pv_id, sum(pv) as pv, sum(clk) as clk, sum(if(str_to_map(args, ',', '=')['sid'] is not null, clk, 0)) as ad_clk\n" +
|
||||
"\t\tselect item_id, pv_id, sum(pv) as pv\n" +
|
||||
"\t\t\t, sum(clk) as clk\n" +
|
||||
"\t\t\t, sum(if(str_to_map(args, ',', '=')['sid'] is not null, clk, 0)) as ad_clk\n" +
|
||||
"\t\t\t, str_to_map(args, ',', '=')['sid'] as ad_session, split_part(str_to_map(args, ',', '=')['scm'], '.', 2) as bucket_id\n" +
|
||||
"\t\tfrom alimama_algo.fund_mlr_n_chicago_user_track_distinct_shark\n" +
|
||||
"\t\twhere ds = 20170627\n" +
|
||||
@@ -106,7 +117,8 @@ public class OdpsSelectTest22 extends TestCase {
|
||||
"\t\t\tsplit_part(str_to_map(args, ',', '=')['scm'], '.', 2)\n" +
|
||||
"\t) UT\n" +
|
||||
"\tleft outer join (\n" +
|
||||
"\t\tselect pv_id as ad_session, item_it as item_id, sum(click_price) as cost, count(*) as clk\n" +
|
||||
"\t\tselect pv_id as ad_session, item_it as item_id, sum(click_price) as cost\n" +
|
||||
"\t\t\t, count(*) as clk\n" +
|
||||
"\t\tfrom alimama_algo.fund_mlr_n_chicago_offline_click\n" +
|
||||
"\t\twhere ds = 20170627\n" +
|
||||
"\t\t\tand hh = 0\n" +
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OdpsSelectTest24 extends TestCase {
|
||||
|
||||
public void test_select() throws Exception {
|
||||
// 1095288847322
|
||||
String sql = "SELECT ta.member_id AS member_id\n" +
|
||||
"\t, ta.city_id\n" +
|
||||
"\t, COUNT(IF(ta.add_date = '${date_minus_1}', 1, NULL)) AS order_cnt\n" +
|
||||
"\t, COUNT(ta.is_open_order) AS open_order_cnt\n" +
|
||||
"\t, COUNT(t1.is_normal_order) AS normal_order_cnt\n" +
|
||||
"\t, SUM(t2.is_master_appointed) AS master_appointed_cnt\n" +
|
||||
"\t, SUM(t1.is_psaz_order) AS psaz_order_cnt\n" +
|
||||
"\t, SUM(t1.is_az_order) AS az_order_cnt\n" +
|
||||
"\t, SUM(t1.is_wx_order) AS wx_order_cnt\n" +
|
||||
"\t, SUM(t1.is_qx_order) AS qx_order_cnt\n" +
|
||||
"\t, SUM(t2.is_trade_complete) AS trade_complete_cnt\n" +
|
||||
"\t, SUM(IF(t2.is_trade_complete = 1, t2.order_price, 0)) AS order_income\n" +
|
||||
"\t, SUM(t2.is_trade_close) AS trade_close_cnt\n" +
|
||||
"FROM (\n" +
|
||||
"\tSELECT order_id\n" +
|
||||
"\t\t, member_id\n" +
|
||||
"\t\t, order_price\n" +
|
||||
"\t\t, region_id\n" +
|
||||
"\t\t, appoint_method\n" +
|
||||
"\t\t, category\n" +
|
||||
"\t\t, serve_types\n" +
|
||||
"\t\t, to_char(from_unixtime(add_time), 'yyyy-mm-dd') AS add_date\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'open', 1, NULL) AS is_open_order\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'normal', 1, NULL) AS is_normal_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\tAND t1.serve_types = 3)\n" +
|
||||
"\t\tOR (t1.category > 1\n" +
|
||||
"\t\tAND t1.serve_types = 2), 1, NULL) AS is_psaz_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\tAND t1.serve_types = 4)\n" +
|
||||
"\t\tOR (t1.category > 1\n" +
|
||||
"\t\tAND t1.serve_types = 3), 1, NULL) AS is_az_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\tAND t1.serve_types = 5)\n" +
|
||||
"\t\tOR (t1.category > 1\n" +
|
||||
"\t\tAND t1.serve_types = 4), 1, NULL) AS is_wx_order\n" +
|
||||
"\t\t, IF(t1.category > 1\n" +
|
||||
"\t\tAND t1.serve_types = 5, 1, NULL) AS is_qx_order\n" +
|
||||
"\tFROM bds_order_base_d\n" +
|
||||
"\tWHERE dt = '${date_minus_1}'\n" +
|
||||
") t1\n" +
|
||||
"LEFT OUTER JOIN (\n" +
|
||||
"\tSELECT order_id\n" +
|
||||
"\t\t, MAX(IF(status = 'master_appointed', 1, 0)) AS is_master_appointed\n" +
|
||||
"\t\t, MAX(IF(status = 'trade_complete', 1, 0)) AS is_trade_complete\n" +
|
||||
"\t\t, MAX(IF(status = 'trade_close', 1, 0)) AS is_trade_close\n" +
|
||||
"\tFROM ods_order_tracking_time_d\n" +
|
||||
"\tWHERE dt = '${date_minus_1}'\n" +
|
||||
"\t\tAND status IN ('master_appointed', 'trade_complete', 'trade_close')\n" +
|
||||
"\tGROUP BY order_id\n" +
|
||||
") t2\n" +
|
||||
"ON t1.order_id = t2.order_id\n" +
|
||||
"LEFT OUTER JOIN (\n" +
|
||||
"\tSELECT region_id\n" +
|
||||
"\t\t, lvl2region_id AS city_id\n" +
|
||||
"\tFROM d_prov_city_district\n" +
|
||||
") t3\n" +
|
||||
"ON t1.region_id = t3.region_id\n" +
|
||||
"WHERE t1.add_date = '${date_minus_1}'\n" +
|
||||
"\tOR t2.order_id IS NOT NULL\n" +
|
||||
"GROUP BY t1.member_id, \n" +
|
||||
"\tt3.city_id";//
|
||||
assertEquals("SELECT ta.member_id AS member_id, ta.city_id\n" +
|
||||
"\t, COUNT(IF(ta.add_date = '${date_minus_1}', 1, NULL)) AS order_cnt\n" +
|
||||
"\t, COUNT(ta.is_open_order) AS open_order_cnt, COUNT(t1.is_normal_order) AS normal_order_cnt\n" +
|
||||
"\t, SUM(t2.is_master_appointed) AS master_appointed_cnt, SUM(t1.is_psaz_order) AS psaz_order_cnt\n" +
|
||||
"\t, SUM(t1.is_az_order) AS az_order_cnt, SUM(t1.is_wx_order) AS wx_order_cnt\n" +
|
||||
"\t, SUM(t1.is_qx_order) AS qx_order_cnt, SUM(t2.is_trade_complete) AS trade_complete_cnt\n" +
|
||||
"\t, SUM(IF(t2.is_trade_complete = 1, t2.order_price, 0)) AS order_income\n" +
|
||||
"\t, SUM(t2.is_trade_close) AS trade_close_cnt\n" +
|
||||
"FROM (\n" +
|
||||
"\tSELECT order_id, member_id, order_price, region_id, appoint_method\n" +
|
||||
"\t\t, category, serve_types\n" +
|
||||
"\t\t, to_char(from_unixtime(add_time), 'yyyy-mm-dd') AS add_date\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'open', 1, NULL) AS is_open_order\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'normal', 1, NULL) AS is_normal_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 3)\n" +
|
||||
"\t\t\tOR (t1.category > 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 2), 1, NULL) AS is_psaz_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 4)\n" +
|
||||
"\t\t\tOR (t1.category > 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 3), 1, NULL) AS is_az_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 5)\n" +
|
||||
"\t\t\tOR (t1.category > 1\n" +
|
||||
"\t\t\t\tAND t1.serve_types = 4), 1, NULL) AS is_wx_order\n" +
|
||||
"\t\t, IF(t1.category > 1\n" +
|
||||
"\t\t\tAND t1.serve_types = 5, 1, NULL) AS is_qx_order\n" +
|
||||
"\tFROM bds_order_base_d\n" +
|
||||
"\tWHERE dt = '${date_minus_1}'\n" +
|
||||
") t1\n" +
|
||||
"LEFT OUTER JOIN (\n" +
|
||||
"\tSELECT order_id\n" +
|
||||
"\t\t, MAX(IF(status = 'master_appointed', 1, 0)) AS is_master_appointed\n" +
|
||||
"\t\t, MAX(IF(status = 'trade_complete', 1, 0)) AS is_trade_complete\n" +
|
||||
"\t\t, MAX(IF(status = 'trade_close', 1, 0)) AS is_trade_close\n" +
|
||||
"\tFROM ods_order_tracking_time_d\n" +
|
||||
"\tWHERE dt = '${date_minus_1}'\n" +
|
||||
"\t\tAND status IN ('master_appointed', 'trade_complete', 'trade_close')\n" +
|
||||
"\tGROUP BY order_id\n" +
|
||||
") t2\n" +
|
||||
"ON t1.order_id = t2.order_id\n" +
|
||||
"LEFT OUTER JOIN (\n" +
|
||||
"\tSELECT region_id, lvl2region_id AS city_id\n" +
|
||||
"\tFROM d_prov_city_district\n" +
|
||||
") t3\n" +
|
||||
"ON t1.region_id = t3.region_id\n" +
|
||||
"WHERE t1.add_date = '${date_minus_1}'\n" +
|
||||
"\tOR t2.order_id IS NOT NULL\n" +
|
||||
"GROUP BY t1.member_id, \n" +
|
||||
"\tt3.city_id", SQLUtils.formatOdps(sql));
|
||||
|
||||
assertEquals("select ta.member_id as member_id, ta.city_id\n" +
|
||||
"\t, count(IF(ta.add_date = '${date_minus_1}', 1, null)) as order_cnt\n" +
|
||||
"\t, count(ta.is_open_order) as open_order_cnt, count(t1.is_normal_order) as normal_order_cnt\n" +
|
||||
"\t, sum(t2.is_master_appointed) as master_appointed_cnt, sum(t1.is_psaz_order) as psaz_order_cnt\n" +
|
||||
"\t, sum(t1.is_az_order) as az_order_cnt, sum(t1.is_wx_order) as wx_order_cnt\n" +
|
||||
"\t, sum(t1.is_qx_order) as qx_order_cnt, sum(t2.is_trade_complete) as trade_complete_cnt\n" +
|
||||
"\t, sum(IF(t2.is_trade_complete = 1, t2.order_price, 0)) as order_income\n" +
|
||||
"\t, sum(t2.is_trade_close) as trade_close_cnt\n" +
|
||||
"from (\n" +
|
||||
"\tselect order_id, member_id, order_price, region_id, appoint_method\n" +
|
||||
"\t\t, category, serve_types\n" +
|
||||
"\t\t, to_char(from_unixtime(add_time), 'yyyy-mm-dd') as add_date\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'open', 1, null) as is_open_order\n" +
|
||||
"\t\t, IF(t1.appoint_method = 'normal', 1, null) as is_normal_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 3)\n" +
|
||||
"\t\t\tor (t1.category > 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 2), 1, null) as is_psaz_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 4)\n" +
|
||||
"\t\t\tor (t1.category > 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 3), 1, null) as is_az_order\n" +
|
||||
"\t\t, IF((t1.category = 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 5)\n" +
|
||||
"\t\t\tor (t1.category > 1\n" +
|
||||
"\t\t\t\tand t1.serve_types = 4), 1, null) as is_wx_order\n" +
|
||||
"\t\t, IF(t1.category > 1\n" +
|
||||
"\t\t\tand t1.serve_types = 5, 1, null) as is_qx_order\n" +
|
||||
"\tfrom bds_order_base_d\n" +
|
||||
"\twhere dt = '${date_minus_1}'\n" +
|
||||
") t1\n" +
|
||||
"left outer join (\n" +
|
||||
"\tselect order_id\n" +
|
||||
"\t\t, max(IF(status = 'master_appointed', 1, 0)) as is_master_appointed\n" +
|
||||
"\t\t, max(IF(status = 'trade_complete', 1, 0)) as is_trade_complete\n" +
|
||||
"\t\t, max(IF(status = 'trade_close', 1, 0)) as is_trade_close\n" +
|
||||
"\tfrom ods_order_tracking_time_d\n" +
|
||||
"\twhere dt = '${date_minus_1}'\n" +
|
||||
"\t\tand status in ('master_appointed', 'trade_complete', 'trade_close')\n" +
|
||||
"\tgroup by order_id\n" +
|
||||
") t2\n" +
|
||||
"on t1.order_id = t2.order_id\n" +
|
||||
"left outer join (\n" +
|
||||
"\tselect region_id, lvl2region_id as city_id\n" +
|
||||
"\tfrom d_prov_city_district\n" +
|
||||
") t3\n" +
|
||||
"on t1.region_id = t3.region_id\n" +
|
||||
"where t1.add_date = '${date_minus_1}'\n" +
|
||||
"\tor t2.order_id is not null\n" +
|
||||
"group by t1.member_id, \n" +
|
||||
"\tt3.city_id", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(3, visitor.getTables().size());
|
||||
assertEquals(20, visitor.getColumns().size());
|
||||
assertEquals(16, visitor.getConditions().size());
|
||||
|
||||
System.out.println(SQLUtils.formatOdps(sql));
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.odps;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OdpsSelectTest25 extends TestCase {
|
||||
|
||||
public void test_select() throws Exception {
|
||||
// 1095288847322
|
||||
String sql = "INSERT overwrite TABLE ids_openapp_dau_d partition(dt = '${lastday}')\n" +
|
||||
"SELECT tt.os,\n" +
|
||||
" tt.ver,\n" +
|
||||
" count(1) AS tt_user,\n" +
|
||||
" sum(tt.tt_cnt) AS tt_cnt,\n" +
|
||||
" count(if(tt.tmp_cnt > 0,1,NULL)) AS tmp_user,\n" +
|
||||
" sum(tt.tmp_cnt) AS tmp_cnt,\n" +
|
||||
" count(if(tt.formal_cnt > 0,1,NULL)) AS formal_user,\n" +
|
||||
" sum(tt.formal_cnt) AS formal_cnt\n" +
|
||||
"FROM\n" +
|
||||
" (SELECT t1.uid,\n" +
|
||||
" t2.os,\n" +
|
||||
" t3.ver,\n" +
|
||||
" count(1) AS tt_cnt,\n" +
|
||||
" count(t1.tmp) AS tmp_cnt,\n" +
|
||||
" count(t1.formal) AS formal_cnt\n" +
|
||||
" FROM\n" +
|
||||
" (SELECT uid,\n" +
|
||||
" array(pv,'all') AS os,\n" +
|
||||
" array(v,'all') AS ver,\n" +
|
||||
" if(utype = 0,1,NULL) AS tmp,\n" +
|
||||
" if(utype = 1,1,NULL) AS formal\n" +
|
||||
" FROM openapp_log_d\n" +
|
||||
" WHERE dt = '${lastday}') t1 LATERAL VIEW explode(t1.os) t2 AS os LATERAL VIEW explode(t1.ver) t3 AS ver\n" +
|
||||
" GROUP BY t1.uid,\n" +
|
||||
" t2.os,\n" +
|
||||
" t3.ver) tt\n" +
|
||||
"WHERE NOT (tt.os = 'all'\n" +
|
||||
" AND tt.ver <> 'all')\n" +
|
||||
"GROUP BY tt.os,\n" +
|
||||
" tt.ver;";//
|
||||
assertEquals("INSERT OVERWRITE TABLE ids_openapp_dau_d PARTITION (dt='${lastday}')\n" +
|
||||
"SELECT tt.os, tt.ver, COUNT(1) AS tt_user\n" +
|
||||
"\t, SUM(tt.tt_cnt) AS tt_cnt\n" +
|
||||
"\t, COUNT(IF(tt.tmp_cnt > 0, 1, NULL)) AS tmp_user\n" +
|
||||
"\t, SUM(tt.tmp_cnt) AS tmp_cnt\n" +
|
||||
"\t, COUNT(IF(tt.formal_cnt > 0, 1, NULL)) AS formal_user\n" +
|
||||
"\t, SUM(tt.formal_cnt) AS formal_cnt\n" +
|
||||
"FROM (\n" +
|
||||
"\tSELECT t1.uid, t2.os, t3.ver, COUNT(1) AS tt_cnt\n" +
|
||||
"\t\t, COUNT(t1.tmp) AS tmp_cnt, COUNT(t1.formal) AS formal_cnt\n" +
|
||||
"\tFROM (\n" +
|
||||
"\t\tSELECT uid, array(pv, 'all') AS os\n" +
|
||||
"\t\t\t, array(v, 'all') AS ver\n" +
|
||||
"\t\t\t, IF(utype = 0, 1, NULL) AS tmp\n" +
|
||||
"\t\t\t, IF(utype = 1, 1, NULL) AS formal\n" +
|
||||
"\t\tFROM openapp_log_d\n" +
|
||||
"\t\tWHERE dt = '${lastday}'\n" +
|
||||
"\t) t1\n" +
|
||||
"\t\tLATERAL VIEW EXPLODE(t1.os) t2 AS os\n" +
|
||||
"\t\tLATERAL VIEW EXPLODE(t1.ver) t3 AS ver\n" +
|
||||
"\tGROUP BY t1.uid, \n" +
|
||||
"\t\tt2.os, \n" +
|
||||
"\t\tt3.ver\n" +
|
||||
") tt\n" +
|
||||
"WHERE NOT (tt.os = 'all'\n" +
|
||||
"AND tt.ver <> 'all')\n" +
|
||||
"GROUP BY tt.os, \n" +
|
||||
"\ttt.ver;", SQLUtils.formatOdps(sql));
|
||||
|
||||
assertEquals("insert overwrite table ids_openapp_dau_d partition (dt='${lastday}')\n" +
|
||||
"select tt.os, tt.ver, count(1) as tt_user\n" +
|
||||
"\t, sum(tt.tt_cnt) as tt_cnt\n" +
|
||||
"\t, count(if(tt.tmp_cnt > 0, 1, null)) as tmp_user\n" +
|
||||
"\t, sum(tt.tmp_cnt) as tmp_cnt\n" +
|
||||
"\t, count(if(tt.formal_cnt > 0, 1, null)) as formal_user\n" +
|
||||
"\t, sum(tt.formal_cnt) as formal_cnt\n" +
|
||||
"from (\n" +
|
||||
"\tselect t1.uid, t2.os, t3.ver, count(1) as tt_cnt\n" +
|
||||
"\t\t, count(t1.tmp) as tmp_cnt, count(t1.formal) as formal_cnt\n" +
|
||||
"\tfrom (\n" +
|
||||
"\t\tselect uid, array(pv, 'all') as os\n" +
|
||||
"\t\t\t, array(v, 'all') as ver\n" +
|
||||
"\t\t\t, if(utype = 0, 1, null) as tmp\n" +
|
||||
"\t\t\t, if(utype = 1, 1, null) as formal\n" +
|
||||
"\t\tfrom openapp_log_d\n" +
|
||||
"\t\twhere dt = '${lastday}'\n" +
|
||||
"\t) t1\n" +
|
||||
"\t\tlateral view explode(t1.os) t2 as os\n" +
|
||||
"\t\tlateral view explode(t1.ver) t3 as ver\n" +
|
||||
"\tgroup by t1.uid, \n" +
|
||||
"\t\tt2.os, \n" +
|
||||
"\t\tt3.ver\n" +
|
||||
") tt\n" +
|
||||
"where not (tt.os = 'all'\n" +
|
||||
"and tt.ver <> 'all')\n" +
|
||||
"group by tt.os, \n" +
|
||||
"\ttt.ver;", SQLUtils.formatOdps(sql, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
|
||||
|
||||
List<SQLStatement> statementList = SQLUtils.parseStatements(sql, JdbcConstants.ODPS);
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(JdbcConstants.ODPS);
|
||||
stmt.accept(visitor);
|
||||
|
||||
// System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
// System.out.println("coditions : " + visitor.getConditions());
|
||||
// System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(2, visitor.getTables().size());
|
||||
assertEquals(6, visitor.getColumns().size());
|
||||
assertEquals(2, visitor.getConditions().size());
|
||||
|
||||
System.out.println(SQLUtils.formatOdps(sql));
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new Column("abc", "name")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -32,7 +32,8 @@ public class OracleFlashbackQueryTest3 extends TestCase {
|
||||
|
||||
String expect = "SELECT DECODE(GROUPING(department_name), 1, 'All Departments', department_name) AS department\n" +
|
||||
"\t, DECODE(GROUPING(job_id), 1, 'All Jobs', job_id) AS job\n" +
|
||||
"\t, COUNT(*) AS \"Total Empl\", AVG(salary) * 12 AS \"Average Sal\"\n" +
|
||||
"\t, COUNT(*) AS \"Total Empl\"\n" +
|
||||
"\t, AVG(salary) * 12 AS \"Average Sal\"\n" +
|
||||
"FROM employees e, departments d\n" +
|
||||
"WHERE d.department_id = e.department_id\n" +
|
||||
"GROUP BY ROLLUP(department_name, job_id);";
|
||||
@@ -42,7 +43,7 @@ public class OracleFlashbackQueryTest3 extends TestCase {
|
||||
|
||||
String text = TestUtils.outputOracle(stmt);
|
||||
|
||||
Assert.assertEquals(expect, text);
|
||||
assertEquals(expect, text);
|
||||
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
@@ -30,15 +30,16 @@ public class OracleListAggTest extends OracleTest {
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
Assert.assertEquals("SELECT prod_id, LISTAGG(cust_first_name || ' ' || cust_last_name, '; ') WITHIN GROUP (ORDER BY amount_sold DESC) AS cust_list" //
|
||||
+ "\nFROM sales, customers"//
|
||||
+ "\nWHERE sales.cust_id = customers.cust_id" //
|
||||
+ "\n\tAND cust_gender = 'M'" //
|
||||
+ "\n\tAND cust_credit_limit = 15000" //
|
||||
+ "\n\tAND prod_id BETWEEN 15 AND 18" //
|
||||
+ "\n\tAND channel_id = 2" //
|
||||
+ "\n\tAND time_id > '01-JAN-01'" //
|
||||
+ "\nGROUP BY prod_id;",//
|
||||
Assert.assertEquals("SELECT prod_id\n" +
|
||||
"\t, LISTAGG(cust_first_name || ' ' || cust_last_name, '; ') WITHIN GROUP (ORDER BY amount_sold DESC) AS cust_list\n" +
|
||||
"FROM sales, customers\n" +
|
||||
"WHERE sales.cust_id = customers.cust_id\n" +
|
||||
"\tAND cust_gender = 'M'\n" +
|
||||
"\tAND cust_credit_limit = 15000\n" +
|
||||
"\tAND prod_id BETWEEN 15 AND 18\n" +
|
||||
"\tAND channel_id = 2\n" +
|
||||
"\tAND time_id > '01-JAN-01'\n" +
|
||||
"GROUP BY prod_id;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
|
||||
@@ -44,14 +44,15 @@ public class OracleSubqueryFactoringTest2 extends TestCase {
|
||||
"\t\tFROM employees\n" +
|
||||
"\t\tWHERE manager_id IS NULL\n" +
|
||||
"\t\tUNION ALL\n" +
|
||||
"\t\tSELECT e.employee_id, e.last_name, e.manager_id, r.reportLevel + 1 AS reportLevel, e.salary\n" +
|
||||
"\t\t\t, e.job_id\n" +
|
||||
"\t\tSELECT e.employee_id, e.last_name, e.manager_id, r.reportLevel + 1 AS reportLevel\n" +
|
||||
"\t\t\t, e.salary, e.job_id\n" +
|
||||
"\t\tFROM org_chart r, employees e\n" +
|
||||
"\t\tWHERE r.eid = e.manager_id\n" +
|
||||
"\t)\n" +
|
||||
"\tSEARCH DEPTH FIRST BY emp_last SET order1\n" +
|
||||
"\tCYCLE hire_date SET is_cycle TO 'Y' DEFAULT 'N'\n" +
|
||||
"SELECT lpad(' ', 2 * reportLevel) || emp_last AS emp_name, eid, mgr_id, salary, job_id\n" +
|
||||
"SELECT lpad(' ', 2 * reportLevel) || emp_last AS emp_name\n" +
|
||||
"\t, eid, mgr_id, salary, job_id\n" +
|
||||
"FROM org_chart\n" +
|
||||
"ORDER BY order1;";
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 1999-2017 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.oracle.create;
|
||||
|
||||
import com.alibaba.druid.sql.OracleTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OracleCreateFunctionTest_0 extends OracleTest {
|
||||
|
||||
public void test_types() throws Exception {
|
||||
String sql = //
|
||||
"CREATE FUNCTION get_bal(acc_no IN NUMBER) \n" +
|
||||
" RETURN NUMBER \n" +
|
||||
" IS acc_bal NUMBER(11,2);\n" +
|
||||
" BEGIN \n" +
|
||||
" SELECT order_total \n" +
|
||||
" INTO acc_bal \n" +
|
||||
" FROM orders \n" +
|
||||
" WHERE customer_id = acc_no; \n" +
|
||||
" RETURN(acc_bal); \n" +
|
||||
" END;";
|
||||
|
||||
OracleStatementParser parser = new OracleStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
assertEquals("CREATE FUNCTION get_bal (\n" +
|
||||
"\tacc_no IN NUMBER\n" +
|
||||
")\n" +
|
||||
"RETURN NUMBER\n" +
|
||||
"AS\n" +
|
||||
"acc_bal NUMBER(11, 2);\n" +
|
||||
"BEGIN\n" +
|
||||
"\tSELECT order_total\n" +
|
||||
"\tINTO acc_bal\n" +
|
||||
"\tFROM orders\n" +
|
||||
"\tWHERE customer_id = acc_no;\n" +
|
||||
"\tRETURN acc_bal;\n" +
|
||||
"END;",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("relationships : " + visitor.getRelationships());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
assertEquals(1, visitor.getTables().size());
|
||||
|
||||
assertEquals(3, visitor.getColumns().size());
|
||||
|
||||
assertTrue(visitor.getColumns().contains(new TableStat.Column("orders", "order_total")));
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class OracleCreateTriggerTest2 extends OracleTest {
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
Assert.assertEquals("CREATE OR REPLEACE TRIGGER projects_idt\n" +
|
||||
Assert.assertEquals("CREATE OR REPLACE TRIGGER projects_idt\n" +
|
||||
"\tBEFORE INSERT\n" +
|
||||
"\tON projects\n" +
|
||||
"\tFOR EACH ROW\n" +
|
||||
|
||||
@@ -88,8 +88,9 @@ public class OracleCreateViewTest2 extends OracleTest {
|
||||
"AS\n" +
|
||||
"SELECT db.db_key, db.db_id, bs.bs_key, bs.bs_recid AS recid, bs.bs_stamp AS stamp\n" +
|
||||
"\t, bs.set_stamp, bs.set_count, bs.bck_type AS backup_type, bs.incr_level AS incremental_level, bs.pieces\n" +
|
||||
"\t, bs.start_time, bs.completion_time, abs((bs.completion_time - bs.start_time) * 86400) AS elapsed_seconds, bs.status\n" +
|
||||
"\t, bs.controlfile_included, bs.input_file_scan_only\n" +
|
||||
"\t, bs.start_time, bs.completion_time\n" +
|
||||
"\t, abs((bs.completion_time - bs.start_time) * 86400) AS elapsed_seconds\n" +
|
||||
"\t, bs.status, bs.controlfile_included, bs.input_file_scan_only\n" +
|
||||
"\t, decode(keep_options, 0, 'NO', 'YES') AS keep\n" +
|
||||
"\t, keep_until\n" +
|
||||
"\t, decode(keep_options, 256, 'LOGS', 512, 'NOLOGS', 1024, 'CONSISTENT', NULL) AS keep_options\n" +
|
||||
|
||||
@@ -119,15 +119,16 @@ public class OracleCreateViewTest6 extends OracleTest {
|
||||
")\n" +
|
||||
"AS\n" +
|
||||
"SELECT ID, GMT_CREATE, utl_raw.cast_to_raw(CREATOR) AS CREATOR, GMT_MODIFIED\n" +
|
||||
"\t, utl_raw.cast_to_raw(MODIFIER) AS MODIFIER, IS_DELETED, utl_raw.cast_to_raw(CONTRACT_PARTY) AS CONTRACT_PARTY\n" +
|
||||
"\t, utl_raw.cast_to_raw(COMPANY_NAME) AS COMPANY_NAME, utl_raw.cast_to_raw(PRODUCT_TYPE) AS PRODUCT_TYPE\n" +
|
||||
"\t, utl_raw.cast_to_raw(PERIOD) AS PERIOD, JOIN, OVER, CONTRACT_TERM\n" +
|
||||
"\t, CONTRACT_CASH, EXEC_CASH, CANCELED_CASH, RECEIVERD_CASH, O_S_CASH\n" +
|
||||
"\t, utl_raw.cast_to_raw(REMARK) AS REMARK, FENTAN_CHECK, TOTAL_CASH, NOT_CONFIRMED\n" +
|
||||
"\t, PRE_RECEIVED, NOT_RECEIVED, CONTRACT_DATE, utl_raw.cast_to_raw(OWNER_1) AS OWNER_1\n" +
|
||||
"\t, AREA_ID_1, utl_raw.cast_to_raw(FIRST_OWNER) AS FIRST_OWNER, FIRST_AREA_ID\n" +
|
||||
"\t, utl_raw.cast_to_raw(CONTRACT_ID) AS CONTRACT_ID, utl_raw.cast_to_raw(IS_RENEW_UPGRADE) AS IS_RENEW_UPGRADE, CATEGORY_ID_1\n" +
|
||||
"\t, CATEGORY_ID_2, FIRST_RECEIPT_DATE, utl_raw.cast_to_raw(RECEIPT_REMARK) AS RECEIPT_REMARK\n" +
|
||||
"\t, utl_raw.cast_to_raw(MODIFIER) AS MODIFIER, IS_DELETED\n" +
|
||||
"\t, utl_raw.cast_to_raw(CONTRACT_PARTY) AS CONTRACT_PARTY, utl_raw.cast_to_raw(COMPANY_NAME) AS COMPANY_NAME\n" +
|
||||
"\t, utl_raw.cast_to_raw(PRODUCT_TYPE) AS PRODUCT_TYPE, utl_raw.cast_to_raw(PERIOD) AS PERIOD\n" +
|
||||
"\t, JOIN, OVER, CONTRACT_TERM, CONTRACT_CASH, EXEC_CASH\n" +
|
||||
"\t, CANCELED_CASH, RECEIVERD_CASH, O_S_CASH, utl_raw.cast_to_raw(REMARK) AS REMARK\n" +
|
||||
"\t, FENTAN_CHECK, TOTAL_CASH, NOT_CONFIRMED, PRE_RECEIVED, NOT_RECEIVED\n" +
|
||||
"\t, CONTRACT_DATE, utl_raw.cast_to_raw(OWNER_1) AS OWNER_1, AREA_ID_1\n" +
|
||||
"\t, utl_raw.cast_to_raw(FIRST_OWNER) AS FIRST_OWNER, FIRST_AREA_ID\n" +
|
||||
"\t, utl_raw.cast_to_raw(CONTRACT_ID) AS CONTRACT_ID, utl_raw.cast_to_raw(IS_RENEW_UPGRADE) AS IS_RENEW_UPGRADE\n" +
|
||||
"\t, CATEGORY_ID_1, CATEGORY_ID_2, FIRST_RECEIPT_DATE, utl_raw.cast_to_raw(RECEIPT_REMARK) AS RECEIPT_REMARK\n" +
|
||||
"\t, utl_raw.cast_to_raw(CONTRACT_SERIAL) AS CONTRACT_SERIAL, IS_MERGED\n" +
|
||||
"FROM TB_002",//
|
||||
SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
|
||||
|
||||
@@ -57,7 +57,8 @@ public class OracleSelectTest38 extends OracleTest {
|
||||
Assert.assertEquals("SELECT *\n" +
|
||||
"FROM (\n" +
|
||||
"\tWITH vw_kreis_statics_t AS (\n" +
|
||||
"\t\t\tSELECT substr(xzqh, 1, 6) AS xzqh, swrslx, SUM(swrs_count) AS acd_totle\n" +
|
||||
"\t\t\tSELECT substr(xzqh, 1, 6) AS xzqh, swrslx\n" +
|
||||
"\t\t\t\t, SUM(swrs_count) AS acd_totle\n" +
|
||||
"\t\t\tFROM (\n" +
|
||||
"\t\t\t\tSELECT xzqh, sglx\n" +
|
||||
"\t\t\t\t\t, CASE \n" +
|
||||
@@ -76,7 +77,8 @@ public class OracleSelectTest38 extends OracleTest {
|
||||
"\t\t, kreis_code, kreis_name, px1, py1, px2\n" +
|
||||
"\t\t, py2\n" +
|
||||
"\tFROM (\n" +
|
||||
"\t\tSELECT xzqh, nvl(MAX(decode(swrslx, '1', acd_totle)), 0) AS less3\n" +
|
||||
"\t\tSELECT xzqh\n" +
|
||||
"\t\t\t, nvl(MAX(decode(swrslx, '1', acd_totle)), 0) AS less3\n" +
|
||||
"\t\t\t, nvl(MAX(decode(swrslx, '2', acd_totle)), 0) AS f3to5\n" +
|
||||
"\t\t\t, nvl(MAX(decode(swrslx, '3', acd_totle)), 0) AS f5to9\n" +
|
||||
"\t\t\t, nvl(MAX(decode(swrslx, '4', acd_totle)), 0) AS more9\n" +
|
||||
@@ -104,7 +106,8 @@ public class OracleSelectTest38 extends OracleTest {
|
||||
assertEquals("select *\n" +
|
||||
"from (\n" +
|
||||
"\twith vw_kreis_statics_t as (\n" +
|
||||
"\t\t\tselect substr(xzqh, 1, 6) as xzqh, swrslx, sum(swrs_count) as acd_totle\n" +
|
||||
"\t\t\tselect substr(xzqh, 1, 6) as xzqh, swrslx\n" +
|
||||
"\t\t\t\t, sum(swrs_count) as acd_totle\n" +
|
||||
"\t\t\tfrom (\n" +
|
||||
"\t\t\t\tselect xzqh, sglx\n" +
|
||||
"\t\t\t\t\t, case \n" +
|
||||
@@ -123,7 +126,8 @@ public class OracleSelectTest38 extends OracleTest {
|
||||
"\t\t, kreis_code, kreis_name, px1, py1, px2\n" +
|
||||
"\t\t, py2\n" +
|
||||
"\tfrom (\n" +
|
||||
"\t\tselect xzqh, nvl(max(decode(swrslx, '1', acd_totle)), 0) as less3\n" +
|
||||
"\t\tselect xzqh\n" +
|
||||
"\t\t\t, nvl(max(decode(swrslx, '1', acd_totle)), 0) as less3\n" +
|
||||
"\t\t\t, nvl(max(decode(swrslx, '2', acd_totle)), 0) as f3to5\n" +
|
||||
"\t\t\t, nvl(max(decode(swrslx, '3', acd_totle)), 0) as f5to9\n" +
|
||||
"\t\t\t, nvl(max(decode(swrslx, '4', acd_totle)), 0) as more9\n" +
|
||||
|
||||
+6
-2
@@ -86,7 +86,9 @@ public class OracleSelectTest64_with_recursive extends OracleTest {
|
||||
"\t\tWHERE t2.parent_id = t1.id\n" +
|
||||
"\t)\n" +
|
||||
"\tSEARCH DEPTH FIRST BY id SET order1\n" +
|
||||
"SELECT id, parent_id, RPAD('.', (lvl - 1) * 2, '.') || id AS tree, lvl\n" +
|
||||
"SELECT id, parent_id\n" +
|
||||
"\t, RPAD('.', (lvl - 1) * 2, '.') || id AS tree\n" +
|
||||
"\t, lvl\n" +
|
||||
"FROM t1\n" +
|
||||
"ORDER BY order1;", text);
|
||||
}
|
||||
@@ -106,7 +108,9 @@ public class OracleSelectTest64_with_recursive extends OracleTest {
|
||||
"\t\twhere t2.parent_id = t1.id\n" +
|
||||
"\t)\n" +
|
||||
"\tsearch DEPTH first by id set order1\n" +
|
||||
"select id, parent_id, RPAD('.', (lvl - 1) * 2, '.') || id as tree, lvl\n" +
|
||||
"select id, parent_id\n" +
|
||||
"\t, RPAD('.', (lvl - 1) * 2, '.') || id as tree\n" +
|
||||
"\t, lvl\n" +
|
||||
"from t1\n" +
|
||||
"order by order1;", text);
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public class SQLServerInsertTest7 extends TestCase {
|
||||
|
||||
SQLServerInsertStatement insertStmt = (SQLServerInsertStatement) stmt;
|
||||
|
||||
Assert.assertEquals(0, insertStmt.getValuesList().size());
|
||||
Assert.assertEquals(10, insertStmt.getColumns().size());
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
assertEquals(0, insertStmt.getValuesList().size());
|
||||
assertEquals(10, insertStmt.getColumns().size());
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
@@ -59,8 +59,11 @@ public class SQLServerInsertTest7 extends TestCase {
|
||||
String formatSql = "INSERT INTO MMS_SETTLEMENT_COM\n" +
|
||||
"\t(handler, handleTime, MID, MERCHANTNAME, TOTALAMT\n" +
|
||||
"\t, ACTUALAMT, paymentMoney, STATUS, SERIAL_NUM, REMARKS)\n" +
|
||||
"SELECT 'admin', getdate(), MID, MERCHANTNAME, SUM(CONVERT(DECIMAL(18, 2), isnull(TOTALAMT, 0))) AS TOTALAMT\n" +
|
||||
"\t, SUM(CONVERT(DECIMAL(18, 2), isnull(ACTUALAMT, 0))) AS ACTUALAMT, SUM(CONVERT(DECIMAL(18, 2), isnull(paymentMoney, 0))) AS paymentMoney, 2, 126\n" +
|
||||
"SELECT 'admin', getdate(), MID, MERCHANTNAME\n" +
|
||||
"\t, SUM(CONVERT(DECIMAL(18, 2), isnull(TOTALAMT, 0))) AS TOTALAMT\n" +
|
||||
"\t, SUM(CONVERT(DECIMAL(18, 2), isnull(ACTUALAMT, 0))) AS ACTUALAMT\n" +
|
||||
"\t, SUM(CONVERT(DECIMAL(18, 2), isnull(paymentMoney, 0))) AS paymentMoney\n" +
|
||||
"\t, 2, 126\n" +
|
||||
"\t, (\n" +
|
||||
"\t\tSELECT REMARKS + ''\n" +
|
||||
"\t\tFROM MMS_SETTLEMENT_COM\n" +
|
||||
@@ -70,7 +73,7 @@ public class SQLServerInsertTest7 extends TestCase {
|
||||
"FROM MMS_SETTLEMENT_COM A\n" +
|
||||
"WHERE ID IN (304, 305, 306, 297, 108, 184)\n" +
|
||||
"GROUP BY MID, MERCHANTNAME";
|
||||
Assert.assertEquals(formatSql, SQLUtils.toSQLServerString(insertStmt));
|
||||
assertEquals(formatSql, SQLUtils.toSQLServerString(insertStmt));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user