Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.plugin.clp;

import com.facebook.presto.spi.relation.RowExpression;

import java.util.Optional;

/**
* Represents the result of converting a Presto RowExpression into a CLP-compatible KQL query.
* There are three possible cases:
* 1. The entire RowExpression is convertible to KQL: `definition` is set, `remainingExpression` is empty.
* 2. Part of the RowExpression is convertible: the KQL part is stored in `definition`,
* and the remaining untranslatable part is stored in `remainingExpression`.
* 3. None of the expression is convertible: the full RowExpression is stored in `remainingExpression`,
* and `definition` is empty.
Comment thread
wraymo marked this conversation as resolved.
Outdated
*/
public class ClpExpression
{
// Optional KQL query string representing the fully or partially translatable part of the expression.
private final Optional<String> definition;
Comment thread
kirkrodrigues marked this conversation as resolved.
Outdated

// The remaining (non-translatable) portion of the RowExpression, if any.
private final Optional<RowExpression> remainingExpression;

public ClpExpression(String definition, RowExpression remainingExpression)
{
this.definition = Optional.ofNullable(definition);
this.remainingExpression = Optional.ofNullable(remainingExpression);
}

// Creates an empty ClpExpression (no KQL definition, no remaining expression).
Comment thread
wraymo marked this conversation as resolved.
Outdated
public ClpExpression()
{
this (null, null);
Comment thread
wraymo marked this conversation as resolved.
Outdated
}

// Creates a ClpExpression from a fully translatable KQL string.
public ClpExpression(String definition)
{
this(definition, null);
}
Comment on lines +48 to +56

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add description to @PARAM tag.

The JavaDoc has an empty @PARAM tag without description.

     /**
      * Creates a ClpExpression from a fully translatable KQL query or column name.
      *
-     * @param pushDownExpression
+     * @param pushDownExpression the KQL query string or column name
      */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Creates a ClpExpression from a fully translatable KQL query or column name.
*
* @param pushDownExpression
*/
public ClpExpression(String pushDownExpression)
{
this(pushDownExpression, null);
}
/**
* Creates a ClpExpression from a fully translatable KQL query or column name.
*
* @param pushDownExpression the KQL query string or column name
*/
public ClpExpression(String pushDownExpression)
{
this(pushDownExpression, null);
}
🤖 Prompt for AI Agents
In presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java
around lines 47 to 55, the JavaDoc for the constructor has an empty @param tag
for pushDownExpression. Add a clear description explaining what
pushDownExpression represents, such as "the fully translatable KQL query or
column name to create the ClpExpression from."


// Creates a ClpExpression from a non-translatable RowExpression.
Comment thread
wraymo marked this conversation as resolved.
Outdated
public ClpExpression(RowExpression remainingExpression)
{
this(null, remainingExpression);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider improving constructor parameter validation.

The constructors currently accept null parameters and wrap them in Optional, which could lead to confusion. Consider making the intent clearer by either:

  1. Using explicit null checks with meaningful parameter names
  2. Providing static factory methods with clearer semantics
// Alternative approach with static factory methods
+public static ClpExpression fullyTranslatable(String definition) {
+    return new ClpExpression(requireNonNull(definition), null);
+}
+
+public static ClpExpression partiallyTranslatable(String definition, RowExpression remaining) {
+    return new ClpExpression(requireNonNull(definition), requireNonNull(remaining));
+}
+
+public static ClpExpression nonTranslatable(RowExpression remaining) {
+    return new ClpExpression(null, requireNonNull(remaining));
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public ClpExpression(String definition, RowExpression remainingExpression)
{
this.definition = Optional.ofNullable(definition);
this.remainingExpression = Optional.ofNullable(remainingExpression);
}
// Creates an empty ClpExpression (no KQL definition, no remaining expression).
public ClpExpression()
{
this (null, null);
}
// Creates a ClpExpression from a fully translatable KQL string.
public ClpExpression(String definition)
{
this(definition, null);
}
// Creates a ClpExpression from a non-translatable RowExpression.
public ClpExpression(RowExpression remainingExpression)
{
this(null, remainingExpression);
}
public ClpExpression(String definition, RowExpression remainingExpression)
{
this.definition = Optional.ofNullable(definition);
this.remainingExpression = Optional.ofNullable(remainingExpression);
}
// Creates an empty ClpExpression (no KQL definition, no remaining expression).
public ClpExpression()
{
this(null, null);
}
// Creates a ClpExpression from a fully translatable KQL string.
public ClpExpression(String definition)
{
this(definition, null);
}
// Creates a ClpExpression from a non-translatable RowExpression.
public ClpExpression(RowExpression remainingExpression)
{
this(null, remainingExpression);
}
// Alternative approach with static factory methods
public static ClpExpression fullyTranslatable(String definition) {
return new ClpExpression(requireNonNull(definition), null);
}
public static ClpExpression partiallyTranslatable(String definition, RowExpression remaining) {
return new ClpExpression(requireNonNull(definition), requireNonNull(remaining));
}
public static ClpExpression nonTranslatable(RowExpression remaining) {
return new ClpExpression(null, requireNonNull(remaining));
}
🤖 Prompt for AI Agents
In presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java
around lines 37 to 59, the constructors accept null parameters and wrap them in
Optional, which can be confusing. To fix this, add explicit null checks in the
constructors to validate parameters and throw IllegalArgumentException if
invalid. Alternatively, refactor by making constructors private and provide
static factory methods with descriptive names for creating instances with
definition, remainingExpression, or empty, to clarify intent and avoid null
usage.

Comment on lines +58 to +66

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add description to @PARAM tag.

The JavaDoc has an empty @PARAM tag without description.

     /**
      * Creates a ClpExpression from a non-translatable RowExpression.
      *
-     * @param remainingExpression
+     * @param remainingExpression the non-translatable RowExpression
      */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Creates a ClpExpression from a non-translatable RowExpression.
*
* @param remainingExpression
*/
public ClpExpression(RowExpression remainingExpression)
{
this(null, remainingExpression);
}
/**
* Creates a ClpExpression from a non-translatable RowExpression.
*
* @param remainingExpression the non-translatable RowExpression
*/
public ClpExpression(RowExpression remainingExpression)
{
this(null, remainingExpression);
}
🤖 Prompt for AI Agents
In presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java
around lines 57 to 65, the JavaDoc for the constructor has an empty @param tag
for remainingExpression. Add a clear description to the @param tag explaining
what remainingExpression represents, such as "the non-translatable RowExpression
to create the ClpExpression from."


public Optional<String> getDefinition()
{
return definition;
}

public Optional<RowExpression> getRemainingExpression()
{
return remainingExpression;
}
Comment on lines +68 to +76

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding JavaDoc for getter methods.

While the getter methods are self-explanatory, adding JavaDoc would improve consistency with the rest of the class and provide clarity about the Optional return types.

+    /**
+     * Returns the KQL query or column name that can be pushed down, if any.
+     *
+     * @return Optional containing the pushdown expression, or empty if none exists
+     */
     public Optional<String> getPushDownExpression()
     {
         return pushDownExpression;
     }

+    /**
+     * Returns the remaining non-translatable RowExpression, if any.
+     *
+     * @return Optional containing the remaining expression, or empty if fully translatable
+     */
     public Optional<RowExpression> getRemainingExpression()
     {
         return remainingExpression;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Optional<String> getPushDownExpression()
{
return pushDownExpression;
}
public Optional<RowExpression> getRemainingExpression()
{
return remainingExpression;
}
/**
* Returns the KQL query or column name that can be pushed down, if any.
*
* @return Optional containing the pushdown expression, or empty if none exists
*/
public Optional<String> getPushDownExpression()
{
return pushDownExpression;
}
/**
* Returns the remaining non-translatable RowExpression, if any.
*
* @return Optional containing the remaining expression, or empty if fully translatable
*/
public Optional<RowExpression> getRemainingExpression()
{
return remainingExpression;
}
🤖 Prompt for AI Agents
In presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java
around lines 68 to 76, the getter methods getPushDownExpression and
getRemainingExpression lack JavaDoc comments. Add concise JavaDoc comments above
each method explaining what the method returns, emphasizing that the return type
is Optional and what it may contain or represent, to maintain consistency and
improve clarity.

}
Comment on lines +26 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding standard object methods for better usability.

The class lacks equals(), hashCode(), and toString() methods, which are typically expected for data classes and would improve testability and debugging capabilities.

+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null || getClass() != obj.getClass()) {
+            return false;
+        }
+        ClpExpression that = (ClpExpression) obj;
+        return pushDownExpression.equals(that.pushDownExpression) &&
+               remainingExpression.equals(that.remainingExpression);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return java.util.Objects.hash(pushDownExpression, remainingExpression);
+    }
+
+    @Override
+    public String toString()
+    {
+        return "ClpExpression{" +
+               "pushDownExpression=" + pushDownExpression +
+               ", remainingExpression=" + remainingExpression +
+               '}';
+    }
🤖 Prompt for AI Agents
In presto-clp/src/main/java/com/facebook/presto/plugin/clp/ClpExpression.java
between lines 26 and 77, the class ClpExpression lacks the standard methods
equals(), hashCode(), and toString(). To fix this, implement these methods to
compare instances based on pushDownExpression and remainingExpression fields,
generate consistent hash codes from these fields, and provide a clear string
representation of the object including its field values. This will improve
usability, testability, and debugging.

Loading