-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handling Origin Time Delayed view (#423)
This PR fixes `Origin Time Delayed` view. It adds 2 aggregations: - geotile grid (bucket one) - centroid (metric one) - and partial implementation of `geo_bounding_box ` query (which is not crucial for this view, it just filter outs coordinates outside bounding box) There are some todos (and missing tests), however as this functionality seems to be orthogonal to other features, I would prefer to handle all issues separately. <img width="1317" alt="image" src="https://github.com/QuesmaOrg/quesma/assets/102958445/0cb5aad4-bef6-40ad-ab10-2c4f8f4ac482">
- Loading branch information
Showing
7 changed files
with
238 additions
and
69 deletions.
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,51 @@ | ||
// Copyright Quesma, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
package bucket_aggregations | ||
|
||
import ( | ||
"context" | ||
"quesma/logger" | ||
"quesma/model" | ||
"strconv" | ||
) | ||
|
||
type GeoTileGrid struct { | ||
ctx context.Context | ||
} | ||
|
||
func NewGeoTileGrid(ctx context.Context) GeoTileGrid { | ||
return GeoTileGrid{ctx: ctx} | ||
} | ||
|
||
func (query GeoTileGrid) IsBucketAggregation() bool { | ||
return true | ||
} | ||
|
||
func (query GeoTileGrid) TranslateSqlResponseToJson(rows []model.QueryResultRow, level int) []model.JsonMap { | ||
if len(rows) > 0 && len(rows[0].Cols) < 3 { | ||
logger.ErrorWithCtx(query.ctx).Msgf( | ||
"unexpected number of columns in geotile_grid aggregation response, len(rows[0].Cols): "+ | ||
"%d, level: %d", len(rows[0].Cols), level, | ||
) | ||
} | ||
var response []model.JsonMap | ||
for _, row := range rows { | ||
zoom := int64(row.Cols[0].Value.(float64)) | ||
x := int64(row.Cols[1].Value.(float64)) | ||
y := int64(row.Cols[2].Value.(float64)) | ||
key := strconv.FormatInt(zoom, 10) + "/" + strconv.FormatInt(x, 10) + "/" + strconv.FormatInt(y, 10) | ||
response = append(response, model.JsonMap{ | ||
"key": key, | ||
"doc_count": row.LastColValue(), | ||
}) | ||
} | ||
return response | ||
} | ||
|
||
func (query GeoTileGrid) String() string { | ||
return "geotile_grid" | ||
} | ||
|
||
func (query GeoTileGrid) PostprocessResults(rowsFromDB []model.QueryResultRow) []model.QueryResultRow { | ||
return rowsFromDB | ||
} |
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,41 @@ | ||
// Copyright Quesma, licensed under the Elastic License 2.0. | ||
// SPDX-License-Identifier: Elastic-2.0 | ||
package metrics_aggregations | ||
|
||
import ( | ||
"context" | ||
"quesma/model" | ||
) | ||
|
||
type GeoCentroid struct { | ||
ctx context.Context | ||
} | ||
|
||
func NewGeoCentroid(ctx context.Context) GeoCentroid { | ||
return GeoCentroid{ctx: ctx} | ||
} | ||
|
||
func (query GeoCentroid) IsBucketAggregation() bool { | ||
return false | ||
} | ||
|
||
func (query GeoCentroid) TranslateSqlResponseToJson(rows []model.QueryResultRow, level int) []model.JsonMap { | ||
location := model.JsonMap{ | ||
"lat": rows[0].Cols[3].Value, | ||
"lon": rows[0].Cols[4].Value, | ||
} | ||
return []model.JsonMap{ | ||
{ | ||
"count": rows[0].Cols[5].Value, | ||
"location": location, | ||
}, | ||
} | ||
} | ||
|
||
func (query GeoCentroid) String() string { | ||
return "geo_centroid" | ||
} | ||
|
||
func (query GeoCentroid) PostprocessResults(rowsFromDB []model.QueryResultRow) []model.QueryResultRow { | ||
return rowsFromDB | ||
} |
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
Oops, something went wrong.