-
Notifications
You must be signed in to change notification settings - Fork 181
[Calcite Engine]Support metadata field #3445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
5960440
f86021f
6c5fc81
6b18f9d
5a28f34
6674503
88afdc6
43349b0
25ee03b
f3828f7
8107574
1f29c87
e01d44e
c4f83ae
7ea78be
275ec03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,23 +5,38 @@ | |
|
|
||
| package org.opensearch.sql.ast.expression; | ||
|
|
||
| import com.google.common.collect.ImmutableList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.Node; | ||
| import org.opensearch.sql.ast.tree.Project; | ||
| import org.opensearch.sql.ast.tree.UnresolvedPlan; | ||
|
|
||
| /** Represent the All fields which is been used in SELECT *. */ | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public class AllFields extends UnresolvedExpression { | ||
| public static final AllFields INSTANCE = new AllFields(); | ||
| /** Whether exclude metadata field by force, only used by calcite engine */ | ||
| final boolean excludeMeta; | ||
|
|
||
| private AllFields() {} | ||
| public static final AllFields INSTANCE_OF_ALL = new AllFields(false); | ||
| public static final AllFields INSTANCE_EXCEPT_META = new AllFields(true); | ||
|
||
|
|
||
| private AllFields(boolean excludeMeta) { | ||
| this.excludeMeta = excludeMeta; | ||
| } | ||
|
|
||
| public static AllFields of() { | ||
| return INSTANCE; | ||
| return INSTANCE_OF_ALL; | ||
| } | ||
|
|
||
| public static AllFields excludeMeta() { | ||
| return INSTANCE_EXCEPT_META; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -33,4 +48,12 @@ public List<? extends Node> getChild() { | |
| public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) { | ||
| return nodeVisitor.visitAllFields(this, context); | ||
| } | ||
|
|
||
| public UnresolvedPlan apply(UnresolvedPlan plan) { | ||
|
||
| if ((plan instanceof Project) && !((Project) plan).isExcluded()) { | ||
| return plan; | ||
| } else { | ||
| return new Project(ImmutableList.of(this)).attach(plan); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,22 +9,43 @@ | |
| import java.util.List; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.ToString; | ||
| import org.opensearch.sql.ast.AbstractNodeVisitor; | ||
| import org.opensearch.sql.ast.expression.Field; | ||
| import org.opensearch.sql.ast.expression.Map; | ||
| import org.opensearch.sql.ast.expression.UnresolvedExpression; | ||
| import org.opensearch.sql.calcite.plan.OpenSearchConstants; | ||
|
|
||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class Rename extends UnresolvedPlan { | ||
| private final List<Map> renameList; | ||
| private UnresolvedPlan child; | ||
|
|
||
| public Rename(List<Map> renameList, UnresolvedPlan child) { | ||
| this.renameList = renameList; | ||
| this.child = child; | ||
| checkRename(); | ||
| } | ||
|
|
||
| public Rename(List<Map> renameList) { | ||
| this.renameList = renameList; | ||
| checkRename(); | ||
| } | ||
|
|
||
| private void checkRename() { | ||
|
||
| renameList.forEach(rename -> checkFieldName(rename.getTarget())); | ||
| } | ||
|
|
||
| private void checkFieldName(UnresolvedExpression expr) { | ||
| if (expr instanceof Field field) { | ||
| String name = field.getField().toString(); | ||
| if (OpenSearchConstants.METADATAFIELD_TYPE_MAP.containsKey(name)) { | ||
| throw new IllegalArgumentException( | ||
| String.format("Cannot use metadata field [%s] in Rename command.", name)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,11 @@ default Map<String, ExprType> getReservedFieldTypes() { | |
| return Map.of(); | ||
| } | ||
|
|
||
| /** Whether include reserved fields in the schema of table */ | ||
| default boolean includeReservedFieldTypes() { | ||
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Implement a {@link LogicalPlan} by {@link PhysicalPlan} in storage engine. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why double “meta”?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alias is a public interface. Could you add some comments in code to illustrate the purpose of this parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will make it private and add comments