-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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
SQL: Fix qualified attribute resolution with CCS #81320
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b33956
Fix qualified attribute resolution with CCS
bpintea 93b1003
Merge branch 'master' into fix/field_qualifier_with_ccs
bpintea e079383
Address review comments
bpintea 90d233b
Merge branch 'master' into fix/field_qualifier_with_ccs
bpintea 7c6c385
Merge branch 'master' into fix/field_qualifier_with_ccs
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Fix qualified attribute resolution with CCS
In case the fields are qualified only by the index name in a cross cluster search query, the field resolution was failing since an attribute's qualification contains the cluster name, while a field's doesn't. This changes the existing `Attribute#qualifiedName()` to return a qualification including the index name only and adds (for completion) a new method, `fullyQualifiedName()`, which will return the 'cluster:index' qualification. This will allow queries like this to work: `SELECT remote_index.field FROM remote_cluster:remote_index` or `SELECT remote_index.field FROM remote_index` when the cluster is provided through the xDBC "cluster" parameter.
- Loading branch information
commit 2b33956c5a80435133b3063eb7f4bf8c6a32f3ec
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,16 @@ | |
*/ | ||
package org.elasticsearch.xpack.ql.expression; | ||
|
||
import org.elasticsearch.core.Tuple; | ||
import org.elasticsearch.xpack.ql.tree.Source; | ||
import org.elasticsearch.xpack.ql.type.DataType; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.elasticsearch.transport.RemoteClusterAware.buildRemoteIndexName; | ||
import static org.elasticsearch.xpack.ql.util.RemoteClusterUtils.splitQualifiedIndex; | ||
|
||
/** | ||
* {@link Expression}s that can be materialized and describe properties of the derived table. | ||
|
@@ -31,6 +34,8 @@ public abstract class Attribute extends NamedExpression { | |
// empty - such as a top level attribute in SELECT cause | ||
// present - table name or a table name alias | ||
private final String qualifier; | ||
// cluster name in the qualifier (if any) | ||
private final String cluster; | ||
|
||
// can the attr be null - typically used in JOINs | ||
private final Nullability nullability; | ||
|
@@ -45,7 +50,14 @@ public Attribute(Source source, String name, String qualifier, Nullability nulla | |
|
||
public Attribute(Source source, String name, String qualifier, Nullability nullability, NameId id, boolean synthetic) { | ||
super(source, name, emptyList(), id, synthetic); | ||
this.qualifier = qualifier; | ||
if (qualifier != null) { | ||
Tuple<String, String> splitQualifier = splitQualifiedIndex(qualifier); | ||
this.cluster = splitQualifier.v1(); | ||
this.qualifier = splitQualifier.v2(); | ||
} else { | ||
this.cluster = null; | ||
this.qualifier = null; | ||
} | ||
this.nullability = nullability; | ||
} | ||
|
||
|
@@ -62,6 +74,10 @@ public String qualifiedName() { | |
return qualifier == null ? name() : qualifier + "." + name(); | ||
} | ||
|
||
public String fullyQualifiedName() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who uses fully qualified name? If there's nobody I would remove it. |
||
return qualifier == null ? name() : buildRemoteIndexName(cluster, qualifier) + "." + name(); | ||
} | ||
|
||
@Override | ||
public Nullability nullable() { | ||
return nullability; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's wrap this functionality (which is just string manipulation) inside
StringUtils
inside ql - those methods can call just delegate behind the scenes.RemoteClusterUtils
might be be folded into that if possible.The upside is we don't depend directly on transport or remote write but rather it's just a
StringUtils.splitCatalog
or something similar.