Skip to content

Commit

Permalink
Modify odps struct output.
Browse files Browse the repository at this point in the history
  • Loading branch information
lingo-xp authored and wenshao committed Dec 12, 2024
1 parent 9c55f11 commit 23bfb31
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1051,33 +1051,6 @@ public boolean visit(OdpsCopyStmt x) {
return false;
}

public boolean visit(SQLStructExpr x) {
List<SQLAliasedExpr> items = x.getItems();
int aliasCount = 0;
for (int i = 0, size = items.size(); i < size; ++i) {
SQLAliasedExpr item = items.get(i);
if (item.getAlias() != null) {
aliasCount++;
}
}
if (aliasCount != items.size()) {
return super.visit(x);
}

print0(ucase ? "NAMED_STRUCT(" : "named_struct(");
for (int i = 0, size = items.size(); i < size; ++i) {
if (i != 0) {
print0(", ");
}
SQLAliasedExpr item = items.get(i);
visit(new SQLIdentifierExpr(item.getAlias()));
print0(", ");
item.getExpr().accept(this);
}
print(')');
return false;
}

@Override
public boolean visit(SQLCurrentTimeExpr x) {
final SQLCurrentTimeExpr.Type type = x.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import java.util.List;

import com.alibaba.druid.DbType;
import com.alibaba.druid.TestUtil;
import com.alibaba.druid.bvt.sql.SQLResourceTest;
import com.alibaba.druid.sql.parser.SQLParserFeature;
import com.alibaba.druid.sql.visitor.VisitorFeature;
import junit.framework.TestCase;
Expand All @@ -28,24 +30,34 @@
import com.alibaba.druid.sql.dialect.odps.parser.OdpsStatementParser;
import com.alibaba.druid.sql.dialect.odps.visitor.OdpsSchemaStatVisitor;
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
import org.junit.Test;

public class OdpsResourceTest extends TestCase {
public class OdpsResourceTest extends SQLResourceTest {
public OdpsResourceTest() {
super(DbType.odps);
}

@Test
public void test_0() throws Exception {
exec_test("bvt/parser/odps-0.txt");
}

@Test
public void test_9() throws Exception {
exec_test("bvt/parser/odps-9.txt");
}

@Test
public void test_10() throws Exception {
exec_test("bvt/parser/odps-10.txt");
}

@Test
public void test_11() throws Exception {
exec_test("bvt/parser/odps-11.txt");
}

@Test
public void test_12() throws Exception {
exec_test("bvt/parser/odps-12.txt");
}
Expand All @@ -54,42 +66,56 @@ public void test_12() throws Exception {
// exec_test("bvt/parser/odps-13.txt");
// }

@Test
public void test_14() throws Exception {
exec_test("bvt/parser/odps-14.txt");
}

@Test
public void test_15() throws Exception {
exec_test("bvt/parser/odps-15.txt");
}

@Test
public void test_16() throws Exception {
exec_test("bvt/parser/odps-16.txt");
}

@Test
public void test_17() throws Exception {
exec_test("bvt/parser/odps-17.txt");
}

@Test
public void test_18() throws Exception {
exec_test("bvt/parser/odps-18.txt");
}

@Test
public void test_19() throws Exception {
exec_test("bvt/parser/odps-19.txt");
}

@Test
public void test_20() throws Exception {
exec_test("bvt/parser/odps-20.txt");
}

@Test
public void test_21() throws Exception {
exec_test("bvt/parser/odps-21.txt");
}

@Test
public void test_22() throws Exception {
exec_test("bvt/parser/odps-22.txt");
}

@Test
public void odps_parse() throws Exception {
fileTest(0, 999, i -> "bvt/parser/odps/" + i + ".txt");
}

public void exec_test(String resource) throws Exception {
String input = TestUtil.getResource(resource);
String[] items = input.split("---------------------------");
Expand All @@ -111,7 +137,7 @@ public void exec_test(String resource) throws Exception {

if (expect != null) {
String result = stmt.toString(VisitorFeature.OutputPrettyFormat);
assertEquals(expect, result);
Assert.assertEquals(expect, result);
}
}
}
9 changes: 9 additions & 0 deletions core/src/test/resources/bvt/parser/odps/0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
select struct(a.b, a.c as c, a.d) from a
--------------------
SELECT STRUCT(a.b, a.c AS c, a.d)
FROM a
------------------------------------------------------------------------------------------------------------------------
select named_struct(a.b, b, a.c, c, a.d, d) from a
--------------------
SELECT named_struct(a.b, b, a.c, c, a.d, d)
FROM a

0 comments on commit 23bfb31

Please sign in to comment.