Skip to content

Commit

Permalink
Add test case for PR to preserve lateral in validations (#100)
Browse files Browse the repository at this point in the history
* add test case for PR to preserve lateral in validations

* improve comments
  • Loading branch information
KevinGe00 authored Apr 9, 2024
1 parent 2a26f20 commit c10eb65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ protected RelDataType validateImpl(RelDataType targetRowType) {
final List<String> nameList = new ArrayList<>();
final List<SqlNode> operands = call.getOperandList();
final SqlValidatorNamespace childNs;
// Skip over fetching for LATERAL namespace since they are not registered, use subquery instead

if (operands.get(0).getKind() == SqlKind.LATERAL) {
// We want to use the underlying select under the lateral operator, not the
// lateral itself, to use as validation for the alias list
SqlNode lateral = operands.get(0);
childNs = validator.getNamespace(((SqlCall) lateral).operand(0));
} else {
Expand Down
15 changes: 15 additions & 0 deletions core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.calcite.sql.fun.SqlLibrary;
import org.apache.calcite.sql.fun.SqlLibraryOperatorTableFactory;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.test.SqlTester;
import org.apache.calcite.sql.type.ArraySqlType;
Expand Down Expand Up @@ -11516,6 +11517,20 @@ private void checkCustomColumnResolving(String table) {
}
}

/** Test case for
* <a href="https://github.com/linkedin/linkedin-calcite/pull/98">
* Preserve LATERAL keyword during validation #98</a>. */
@Test
public void testLateralKeywordExistsAfterValidation() throws SqlParseException {
String sql = "SELECT * FROM emp CROSS JOIN LATERAL "
+ "(SELECT * FROM dept WHERE deptno = emp.deptno)";

SqlNode node = tester.parseQuery(sql);
final SqlValidator validator = tester.getValidator();
final SqlNode validatedNode = validator.validate(node);

assertTrue(validatedNode.toString().contains("LATERAL"));
}
}

// End SqlValidatorTest.java

0 comments on commit c10eb65

Please sign in to comment.