imply-cheddar commented on a change in pull request #12241:
URL: https://github.com/apache/druid/pull/12241#discussion_r802315644
##########
File path:
sql/src/main/java/org/apache/druid/sql/calcite/expression/DruidExpression.java
##########
@@ -32,127 +32,303 @@
import org.apache.druid.segment.virtual.ExpressionVirtualColumn;
import javax.annotation.Nullable;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
/**
+ * todo(clint): rewrite javadocs
+ *
* Represents two kinds of expression-like concepts that native Druid queries
support:
*
* (1) SimpleExtractions, which are direct column access, possibly with an
extractionFn
* (2) native Druid expressions.
*/
public class DruidExpression
{
+ public enum NodeType
+ {
+ /**
+ * constant value
+ */
+ LITERAL,
+ /**
+ * Identifier for a direct physical or virtual column access (column name
or virtual column name)
+ */
+ IDENTIFIER,
+ /**
+ * Standard native druid expression, which can compute a string that can
be parsed into {@link Expr}, or used
+ * as an {@link ExpressionVirtualColumn}
+ */
+ EXPRESSION,
+ /**
+ * Expression backed by a specialized {@link VirtualColumn}, which might
provide more optimized evaluation than
+ * is possible with the standard
+ */
+ SPECIALIZED
+ }
+
// Must be sorted
private static final char[] SAFE_CHARS = "
,._-;:(){}[]<>!@#$%^&*`~?/".toCharArray();
+ private static final VirtualColumnBuilder DEFAULT_VIRTUAL_COLUMN_BUILDER =
new ExpressionVirtualColumnBuilder();
static {
Arrays.sort(SAFE_CHARS);
}
- @Nullable
- private final SimpleExtraction simpleExtraction;
- private final String expression;
- private final TrinaryFn<String, ColumnType, ExprMacroTable, VirtualColumn>
virtualColumnFn;
+ private static String escape(final String s)
+ {
+ final StringBuilder escaped = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) {
+ final char c = s.charAt(i);
+ if (Character.isLetterOrDigit(c) || Arrays.binarySearch(SAFE_CHARS, c)
>= 0) {
+ escaped.append(c);
+ } else {
+
escaped.append("\\u").append(BaseEncoding.base16().encode(Chars.toByteArray(c)));
+ }
+ }
+ return escaped.toString();
+ }
- private DruidExpression(@Nullable final SimpleExtraction simpleExtraction,
final String expression, @Nullable final TrinaryFn<String, ColumnType,
ExprMacroTable, VirtualColumn> virtualColumnFn)
Review comment:
right.. it's private. of course, uhhhh, the diff made it hard for me to
see that :P
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]