Skip to content

Commit

Permalink
fix(parser): failed to recognize the schema or package name from an a…
Browse files Browse the repository at this point in the history
…nonymous block (#3069)

* fix anonymous block parse error

* fix anonymous block parse error

* response to pr comments
  • Loading branch information
yhilmare authored Jul 31, 2024
1 parent 3bb7242 commit b99e661
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client
Submodule client updated 141 files
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.oceanbase.tools.sqlparser.oboracle.OBParser.Var_nameContext;
import com.oceanbase.tools.sqlparser.oboracle.PLParser.IdentifierContext;
import com.oceanbase.tools.sqlparser.oboracle.PLParser.Pl_schema_nameContext;
import com.oceanbase.tools.sqlparser.oboracle.PLParser.Sql_stmtContext;
import com.oceanbase.tools.sqlparser.statement.Expression;
import com.oceanbase.tools.sqlparser.statement.common.RelationFactor;
import com.oceanbase.tools.sqlparser.statement.expression.FunctionCall;
Expand Down Expand Up @@ -420,6 +421,18 @@ public RelationFactor visitPl_schema_name(Pl_schema_nameContext ctx) {
return null;
}

@Override
public RelationFactor visitSql_stmt(Sql_stmtContext ctx) {
try {
OBOracleRelationFactorVisitor visitor = new OBOracleRelationFactorVisitor();
visitor.visit(ctx);
identities.addAll(visitor.getIdentities());
} catch (Exception e) {
// eat the exception
}
return null;
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static org.junit.Assert.*;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -60,6 +62,23 @@ public void test() {
}
}

@Test
public void listDBSchemasWithSqlTypes_anonymousBlock_listSucceed() {
String pl = "DECLARE\n"
+ " i VARCHAR2(300);\n"
+ "BEGIN\n"
+ " select ps_auto_refresh_publish_pkg.getloopup_meaning('YES_NO', 'Y') into i from dual;\n"
+ " dbms_output.put_line(i);\n"
+ "END;";
Map<DBSchemaIdentity, Set<SqlType>> actual = DBSchemaExtractor.listDBSchemasWithSqlTypes(
Collections.singletonList(SqlTuple.newTuple(pl)), DialectType.OB_ORACLE, "aps");
Map<DBSchemaIdentity, Set<SqlType>> expect = new HashMap<>();
DBSchemaIdentity dbSchemaIdentity = new DBSchemaIdentity();
dbSchemaIdentity.setSchema("PS_AUTO_REFRESH_PUBLISH_PKG");
expect.put(dbSchemaIdentity, Collections.singleton(SqlType.OTHERS));
Assert.assertEquals(expect, actual);
}

@Data
@NoArgsConstructor
@AllArgsConstructor
Expand Down

0 comments on commit b99e661

Please sign in to comment.