4444 * Each query in the resulting query will be a conjunction of all queries from the input lists at the same position.
4545 * In addition, we support an optional pre-join filter that will be applied to all queries if it is pushable.
4646 * If the pre-join filter cannot be pushed down to Lucene, it will be ignored.
47+ * This class is used in the context of a lookup join, where we need to generate a query for each row of the left dataset.
48+ * The query is then used to fetch the matching rows from the right dataset.
49+ * The class supports two types of joins:
50+ * 1. Field-based join: The join conditions are based on the equality of fields from the left and right datasets.
51+ * 2. Expression-based join: The join conditions are based on a complex expression that can involve multiple fields and operators.
4752 */
4853public class ExpressionQueryList implements LookupEnrichQueryGenerator {
4954 private final List <QueryList > queryLists ;
@@ -64,6 +69,20 @@ private ExpressionQueryList(
6469 buildPreJoinFilter (rightPreJoinPlan , clusterService );
6570 }
6671
72+ /**
73+ * Creates a new {@link ExpressionQueryList} for a field-based join.
74+ * A field-based join is a join where the join conditions are based on the equality of fields from the left and right datasets.
75+ * For example | LOOKUP JOIN on field1, field2, field3
76+ * The query lists are generated from the join conditions.
77+ * The pre-join filter is an optional filter that is applied to the right dataset before the join.
78+ * @param queryLists The list of query lists that will be combined.
79+ * @param context The search execution context.
80+ * @param rightPreJoinPlan The physical plan for the right side of the join.
81+ * @param clusterService The cluster service.
82+ * @param aliasFilter The alias filter.
83+ * @return A new {@link ExpressionQueryList} for a field-based join.
84+ * @throws IllegalArgumentException if the number of query lists is less than 2 and there is no pre-join filter.
85+ */
6786 public static ExpressionQueryList fieldBasedJoin (
6887 List <QueryList > queryLists ,
6988 SearchExecutionContext context ,
@@ -77,6 +96,22 @@ public static ExpressionQueryList fieldBasedJoin(
7796 return new ExpressionQueryList (queryLists , context , rightPreJoinPlan , clusterService , aliasFilter );
7897 }
7998
99+ /**
100+ * Creates a new {@link ExpressionQueryList} for an expression-based join.
101+ * An expression-based join is a join where the join conditions are based on a complex expression
102+ * that can involve multiple fields and operators.
103+ * Example | LOOKUP JOIN on left_field > right_field AND left_field2 == right_field2
104+ * The query lists are generated from the join conditions.
105+ * The pre-join filter is an optional filter that is applied to the right dataset before the join.
106+ * @param context The search execution context.
107+ * @param rightPreJoinPlan The physical plan for the right side of the join.
108+ * @param clusterService The cluster service.
109+ * @param request The transport request.
110+ * @param aliasFilter The alias filter.
111+ * @param warnings The warnings.
112+ * @return A new {@link ExpressionQueryList} for an expression-based join.
113+ * @throws IllegalStateException if the join conditions are null.
114+ */
80115 public static ExpressionQueryList expressionBasedJoin (
81116 SearchExecutionContext context ,
82117 PhysicalPlan rightPreJoinPlan ,
@@ -207,6 +242,13 @@ private void buildPreJoinFilter(PhysicalPlan rightPreJoinPlan, ClusterService cl
207242 }
208243 }
209244
245+ /**
246+ * Returns the query at the given position.
247+ * The query is a conjunction of all queries from the input lists at the same position.
248+ * If a pre-join filter exists, it is also added to the query.
249+ * @param position The position of the query to return.
250+ * @return The query at the given position, or null if any of the match fields are null.
251+ */
210252 @ Override
211253 public Query getQuery (int position ) {
212254 BooleanQuery .Builder builder = new BooleanQuery .Builder ();
@@ -226,6 +268,12 @@ public Query getQuery(int position) {
226268 return builder .build ();
227269 }
228270
271+ /**
272+ * Returns the number of positions in the query list.
273+ * The number of positions is the same for all query lists.
274+ * @return The number of positions in the query list.
275+ * @throws IllegalArgumentException if the query lists have different position counts.
276+ */
229277 @ Override
230278 public int getPositionCount () {
231279 int positionCount = queryLists .get (0 ).getPositionCount ();
0 commit comments