SQL: Support pattern against compatible indices#34718
Conversation
Extend querying support on multiple indices from being strictly identical to being just compatible. Use FieldCapabilities API (extended through elastic#33803) for mapping merging. Close elastic#31837 elastic#31611
|
Pinging @elastic/es-search-aggs |
astefan
left a comment
There was a problem hiding this comment.
LGTM. Left some really minor comments, mostly based on picky concerns.
| } | ||
| if (fieldCap.isSearchable() && fieldCap.nonSearchableIndices() != null) { | ||
| errorMessage.append("[" + indexPattern + "] points to indices with incompatible mappings: "); | ||
| errorMessage.append("field [" + name + "] is searchable expect in "); |
There was a problem hiding this comment.
Typo for expect, should have been except.
| case KEYWORD: | ||
| int length = DataType.KEYWORD.defaultPrecision; | ||
| boolean normalized = false; | ||
| field = new KeywordEsField(fieldName, props, caps.isAggregatable(), length, normalized); |
There was a problem hiding this comment.
Why just not passing false to the constructor, but using the normalized boolean?
There was a problem hiding this comment.
Mainly to not forget about it - I've added a comment regarding its presence.
| EsField field = null; | ||
| Map<String, EsField> props = hasChildren ? new TreeMap<>() : emptyMap(); | ||
|
|
||
| // not currently present, means it's a parent field - currently just return it as an OBJECT |
There was a problem hiding this comment.
I don't understand this comment. This should be a valid statement when there is no dot (no subfields left), but the line it's put before of, doesn't indicate this assumption? Sorry if I missed anything.
There was a problem hiding this comment.
Old comment, irrelevant. Removed it.
| try (Connection c = esJdbc()) { | ||
| SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT * FROM test").executeQuery()); | ||
| assertEquals("Found 1 problem(s)\nline 1:15: [test] doesn't have any types so it is incompatible with sql", e.getMessage()); | ||
| //assertEquals("Found 1 problem(s)\nline 1:15: [test] doesn't have any types so it is incompatible with sql", e.getMessage()); |
There was a problem hiding this comment.
Why not deleting this line altogether?
| String mode = randomFrom("jdbc", "plain"); | ||
| expectBadRequest(() -> runSql(mode, "SELECT * FROM test"), | ||
| containsString("1:15: [test] doesn't have any types so it is incompatible with sql")); | ||
| //containsString("1:15: [test] doesn't have any types so it is incompatible with sql")); |
matriv
left a comment
There was a problem hiding this comment.
Looks Good!!
Minor and just a personal preference: I don't like so much the caps abbreviation for capabilities because it's commonly used for capitalisation. I don't have a good suggestion though... maybe capbs :-) ?
Also left a question for the error message testing.
| .indicesOptions(IndicesOptions.lenientExpandOpen()); | ||
| } | ||
|
|
||
| // Concrete indices still uses get mapping |
There was a problem hiding this comment.
maybe add a TODO to be more clear?
There was a problem hiding this comment.
it's rather WIP blocked by : #34071
As this is high on my list, I'd like that as is instead of a TODO (which typically suggests uncompleted work) - fro 6.5.x there's no much we can do on this front...
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/analysis/index/IndexResolver.java
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/analysis/index/IndexResolver.java
Show resolved
Hide resolved
| .indicesOptions(IndicesOptions.lenientExpandOpen()); | ||
| } | ||
|
|
||
| // Concrete indices still uses get mapping |
There was a problem hiding this comment.
Maybe add a TODO to be more clear?
| if (errorMessage.length() > 0) { | ||
| errorMessage.append(", "); | ||
| } | ||
| errorMessage.append("["); |
There was a problem hiding this comment.
Is this tested with multiple entries?
There was a problem hiding this comment.
If you're asking about the error message, yes in IndexResolverTests (e.g. testMergeIncompatibleTypes).
There was a problem hiding this comment.
I was confused with the StringBuilder here, as you later on insert(0 for the prefix of the message.
You could use an ArrayList for the type.getKey() and a StringJoiner to append them to the StringBuilder.
Really minor, just a suggestion.
|
@matriv fieldCaps is already used inside the public API and through-out the code. I guess it's just another case of overloading : see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html (the API name is |
* master: (24 commits) ingest: better support for conditionals with simulate?verbose (elastic#34155) [Rollup] Job deletion should be invoked on the allocated task (elastic#34574) [DOCS] .Security index is never auto created (elastic#34589) CCR: Requires soft-deletes on the follower (elastic#34725) re-enable bwc tests (elastic#34743) Empty GetAliases authorization fix (elastic#34444) INGEST: Document Processor Conditional (elastic#33388) [CCR] Add total fetch time leader stat (elastic#34577) SQL: Support pattern against compatible indices (elastic#34718) [CCR] Auto follow pattern APIs adjustments (elastic#34518) [Test] Remove dead code from ExceptionSerializationTests (elastic#34713) A small typo in migration-assistance doc (elastic#34704) ingest: processor stats (elastic#34724) SQL: Implement IN(value1, value2, ...) expression. (elastic#34581) Tests: Add checks to GeoDistanceQueryBuilderTests (elastic#34273) INGEST: Rename Pipeline Processor Param. (elastic#34733) Core: Move IndexNameExpressionResolver to java time (elastic#34507) [DOCS] Force Merge: clarify execution and storage requirements (elastic#33882) TESTING.asciidoc fix examples using forbidden annotation (elastic#34515) SQL: Implement `CONVERT`, an alternative to `CAST` (elastic#34660) ...
Extend querying support on multiple indices from being strictly
identical to being just compatible.
Use FieldCapabilities API (extended through #33803) for mapping merging.
Close #31837 #31611