Skip to content

HIVE-29612: LATERAL VIEW OUTER doesn't work with CBO enabled#6482

Open
soumyakanti3578 wants to merge 3 commits into
apache:masterfrom
soumyakanti3578:HIVE-29612
Open

HIVE-29612: LATERAL VIEW OUTER doesn't work with CBO enabled#6482
soumyakanti3578 wants to merge 3 commits into
apache:masterfrom
soumyakanti3578:HIVE-29612

Conversation

@soumyakanti3578
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Support LATERAL VIEW OUTER with CBO enabled

Why are the changes needed?

https://issues.apache.org/jira/browse/HIVE-29612

Does this PR introduce any user-facing change?

No

How was this patch tested?

mvn -pl itests/qtest test -Pitests -Dtest=TestMiniLlapLocalCliDriver -Dtest.output.overwrite=true -Dqfile="lateral_view_outer_cbo.q"

@soumyakanti3578 soumyakanti3578 marked this pull request as ready for review May 14, 2026 19:11
Comment thread ql/src/java/org/apache/hadoop/hive/ql/parse/CalcitePlanner.java Outdated
Comment thread ql/src/java/org/apache/hadoop/hive/ql/parse/relnodegen/LateralViewPlan.java Outdated
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@rubenada rubenada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super familiar with this code (yet), but changes LGTM.
The only detail is the new boolean flag HiveTableFunctionScan#outer, which seems a bit ad-hoc. I wonder if in the future we'd need for it to be something more "generic" (like an enum), although atm this seems a bit overengineering if we only need to represent one value.

return lateralView.getToken().getType() != HiveParser.TOK_LATERAL_VIEW_OUTER;
boolean isCBOSupportedLateralView() {
// Both LATERAL VIEW and LATERAL VIEW OUTER are supported in CBO.
return !this.conf.getBoolVar(HiveConf.ConfVars.HIVE_CBO_RETPATH_HIVEOP);
Copy link
Copy Markdown
Contributor

@thomasrebele thomasrebele May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the result didn't depend on the HIVE_CBO_RETPATH_HIVEOP conf option. Maybe it should still return true if lateralView.getToken().getType() == HiveParser.TOK_LATERAL_VIEW?

Could you please explain why using that conf option here? It's description is Flag to control calcite plan to hive operator conversion, but I don't understand its purpose.

Copy link
Copy Markdown
Contributor

@kasakrisz kasakrisz May 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomasrebele
CBO return path is a different implementation of transforming the logical plan to Hive operators. It skips the AST conversion and converts Calcite operators directly to Hive operators. Maybe I'm missing something but I haven't found any change regarding this conversion in this patch.

@soumyakanti3578
Does lateral views in general is supported in CBO return path?
If yes could you please implement the lateral view outer too. I assume it would affect only 1-2 files and it would fit into the scope of this patch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither LATERAL VIEW nor LATERAL VIEW OUTER work with CBO return path. I'll create a separate ticket for them, as I don't think there's a ticket for them here: https://issues.apache.org/jira/browse/HIVE-9132

So the current condition in isCBOSupportedLateralView() is true for both types of LATERAL VIEW when CBO is enabled (If CBO is not enabled we take a different path), and it is false only when HIVE_CBO_RETPATH_HIVEOP is true (non default path for CBO). So I think the condition correctly reflects the current state.

* @param node AST node
* @return true if node is of lateral view or lateral view outer; false otherwise.
*/
public static boolean isASTNodeLateralViewOrOuter(ASTNode node) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit.: I think we can name this just simply isASTNodeLateralView because IIUC lateral view outer is just a variation of lateral views. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can rename this method in the next commit. 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants