-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
ESQL Support loading points from source into WKB blocks #103698
Merged
craigtaverner
merged 50 commits into
elastic:main
from
craigtaverner:esql_points_from_source_wkb
Jan 8, 2024
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
261bf04
ESQL reading points from source
craigtaverner eb47224
Initial support for BytesRefBlock to support WKB for Geometries
craigtaverner 081468e
Update docs/changelog/103698.yaml
craigtaverner 17ae512
Fixed changelog files
craigtaverner 4cbac42
Remove support for PointBlock
craigtaverner 3b0c89d
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner 895cad1
One change from code review
craigtaverner 60985fe
Removed some leftovers from the PointBlock removal
craigtaverner 35c5df0
Some code-review and TODO checks
craigtaverner eeeffda
Some code-review and TODO checks, and deal with Plan serialization
craigtaverner 0487203
Fixed failing tests with point WKT rendering
craigtaverner cfc4341
Revert stab at implementing forStats for doc-values vs source
craigtaverner 1e6e744
Disabled failing test
craigtaverner 8c5638e
Use max precision when serializing points to XContent
craigtaverner b96933b
Removed unused class from PointBlock code
craigtaverner db2094b
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner 22f631f
Simplifications from code review
craigtaverner 1b41302
Remove intermediate WKT from GeoPointFieldMapper
craigtaverner 4d9eed2
Refactor WKBTopNEncoder to use length prefix encoding
craigtaverner e0c869d
Fix failing test
craigtaverner 1ead4ce
Remove WKBTopNEncoder since DefaultUnsortableTopNEncoder can do the job
craigtaverner d699483
Cleanup from code review
craigtaverner bf1ab97
Remove concrete SpatialPoint class
craigtaverner c62e5aa
Bring back SpatialPointTests
craigtaverner 935bfd6
Reduce object creation in some tests
craigtaverner 5bcbaca
Removed unused code
craigtaverner 3e89588
Removed unused code from earlier versions
craigtaverner 07e162a
Tests were testing cases that no longer apply
craigtaverner cb436f5
Tests were testing cases that no longer apply
craigtaverner 378614f
We need to consider WKB in PlanNamedTypes mixed-cluster
craigtaverner a72d0c2
Removed SpatialPoint from PlanNamedTypes
craigtaverner 572e60f
Removed one more artifact of using SpatialPoint in tests
craigtaverner f1a3600
Some work towards removing creating SpatialPoints
craigtaverner 0f1a58b
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner d0f6a12
Updated GeoPointFieldMapperTests after merge from main
craigtaverner 8dffba7
Get row-stride-reader test working
craigtaverner d1d4ce6
Geo flaky tests to work more reliably
craigtaverner 084d08e
Removed defensive coding in plan serialization
craigtaverner c176db1
Simplify and ensure error is thrown on wrong type
craigtaverner 4509eab
Do version checks on reading plan from PlanStreamInput
craigtaverner 97f5589
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner d18e3a9
Mute failing test
craigtaverner a830c79
Use specific TransportVersions for point literal in query plans
craigtaverner a11ebe0
Fixed failing test after merge with main
craigtaverner b69889e
Fixed failing test after merge with main, with nullValue from source
craigtaverner 1927ec6
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner bb74171
Fixed compile error from previous fix with nullValues
craigtaverner 6500d83
It seems mixed cluster yaml tests don't work
craigtaverner 82d95b6
Merge branch 'main' into esql_points_from_source_wkb
elasticmachine 3fd2b18
Merge remote-tracking branch 'origin/main' into esql_points_from_sour…
craigtaverner 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 103698 | ||
summary: Reading points from source to reduce precision loss | ||
area: ES|QL | ||
type: enhancement | ||
issues: [] |
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
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
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
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
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
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
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
103 changes: 103 additions & 0 deletions
103
server/src/test/java/org/elasticsearch/common/geo/SpatialPointTests.java
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.common.geo; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.lessThan; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class SpatialPointTests extends ESTestCase { | ||
|
||
public void testEqualsAndHashcode() { | ||
iverase marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int i = 0; i < 100; i++) { | ||
SpatialPoint point = randomGeoPoint(); | ||
GeoPoint geoPoint = new GeoPoint(point); | ||
TestPoint testPoint = new TestPoint(point); | ||
TestPoint testPoint2 = new TestPoint(point); | ||
assertEqualsAndHashcode("Same point", point, point); | ||
assertEqualsAndHashcode("Same geo-point", point, geoPoint); | ||
assertNotEqualsAndHashcode("Same location, but different class", point, testPoint); | ||
assertEqualsAndHashcode("Same location, same class", testPoint, testPoint2); | ||
} | ||
} | ||
|
||
public void testCompareTo() { | ||
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. maybe we should add a test where two different subclasses compare to false? |
||
for (int i = 0; i < 100; i++) { | ||
SpatialPoint point = randomValueOtherThanMany(p -> p.getX() < -170 || p.getX() > 170, ESTestCase::randomGeoPoint); | ||
GeoPoint smaller = new GeoPoint(point.getY(), point.getX() - 1); | ||
GeoPoint bigger = new GeoPoint(point.getY(), point.getX() + 1); | ||
TestPoint testSmaller = new TestPoint(smaller); | ||
TestPoint testBigger = new TestPoint(bigger); | ||
assertThat(smaller + " smaller than " + point, smaller.compareTo(point), lessThan(0)); | ||
assertThat(bigger + " bigger than " + point, bigger.compareTo(point), greaterThan(0)); | ||
assertThat(testSmaller + " smaller than " + testBigger, testSmaller.compareTo(testBigger), lessThan(0)); | ||
// TestPoint always greater than GeoPoint | ||
assertThat(testSmaller + " bigger than " + point, testSmaller.compareTo(point), greaterThan(0)); | ||
assertThat(testBigger + " bigger than " + point, testBigger.compareTo(point), greaterThan(0)); | ||
} | ||
} | ||
|
||
private void assertEqualsAndHashcode(String message, SpatialPoint a, SpatialPoint b) { | ||
assertThat("Equals: " + message, a, equalTo(b)); | ||
assertThat("Hashcode: " + message, a.hashCode(), equalTo(b.hashCode())); | ||
assertThat("Compare: " + message, a.compareTo(b), equalTo(0)); | ||
} | ||
|
||
private void assertNotEqualsAndHashcode(String message, SpatialPoint a, SpatialPoint b) { | ||
assertThat("Equals: " + message, a, not(equalTo(b))); | ||
assertThat("Hashcode: " + message, a.hashCode(), not(equalTo(b.hashCode()))); | ||
assertThat("Compare: " + message, a.compareTo(b), not(equalTo(0))); | ||
} | ||
|
||
/** | ||
* This test class used to be trivial, when SpatialPoint was a concrete class. | ||
* If we ever revert back to a concrete class, we can simplify this test class. | ||
* The only requirement is that it extends SpatialPoint, but have a different class name. | ||
*/ | ||
private static class TestPoint implements SpatialPoint { | ||
double x; | ||
double y; | ||
|
||
private TestPoint(SpatialPoint template) { | ||
this.x = template.getX(); | ||
this.y = template.getY(); | ||
} | ||
|
||
@Override | ||
public double getX() { | ||
return x; | ||
} | ||
|
||
@Override | ||
public double getY() { | ||
return y; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * 31 * getClass().getSimpleName().hashCode() + 31 * Double.hashCode(x) + Double.hashCode(y); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (obj == null || getClass() != obj.getClass()) return false; | ||
SpatialPoint point = (SpatialPoint) obj; | ||
return (Double.compare(point.getX(), x) == 0) && Double.compare(point.getY(), y) == 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toWKT(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
It makes me feel uneasy, cannot we reuse the BytesRef reader as we are reading an array of bytes?
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.
Right now we need this to get to the code in the 'Geometries' BlockSourceReader, but as that can get simplified, perhaps this can too.