Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.data.type.ExprCoreType;
import org.opensearch.sql.data.type.ExprType;
import org.opensearch.sql.data.utils.ComparableLinkedHashMap;
import org.opensearch.sql.storage.bindingtuple.BindingTuple;
import org.opensearch.sql.storage.bindingtuple.LazyBindingTuple;

Expand Down Expand Up @@ -44,7 +45,7 @@ public Object value() {

@Override
public Object valueForCalcite() {
LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
ComparableLinkedHashMap<String, Object> resultMap = new ComparableLinkedHashMap<>();
for (Entry<String, ExprValue> entry : valueMap.entrySet()) {
resultMap.put(entry.getKey(), entry.getValue().valueForCalcite());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.sql.data.utils;

import java.util.LinkedHashMap;

public class ComparableLinkedHashMap<K, V> extends LinkedHashMap<K, V>
implements Comparable<ComparableLinkedHashMap<K, V>> {

public ComparableLinkedHashMap() {
super();
}

public ComparableLinkedHashMap(int initialCapacity) {
super(initialCapacity);
}

public ComparableLinkedHashMap(int initialCapacity, float loadFactor) {
super(initialCapacity, loadFactor);
}

@Override
public int compareTo(ComparableLinkedHashMap<K, V> other) {
if (this.isEmpty() && other.isEmpty()) {
return 0;
}
if (this.isEmpty()) {
return -1;
}
if (other.isEmpty()) {
return 1;
}

V thisFirstValue = this.values().iterator().next();
V otherFirstValue = other.values().iterator().next();

if (thisFirstValue instanceof Comparable) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only comparing the first element?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to compare recursively

return ((Comparable) thisFirstValue).compareTo(otherFirstValue);
}

return thisFirstValue.toString().compareTo(otherFirstValue.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
setup:
- do:
indices.create:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
log:
properties:
url:
properties:
message:
type: text
fields:
keyword:
type: keyword
ignore_above: 256
time:
type: long
message_alias:
type: alias
path: log.url.message
time_alias:
type: alias
path: log.url.time

- do:
query.settings:
body:
transient:
plugins.calcite.enabled : true

---
teardown:
- do:
query.settings:
body:
transient:
plugins.calcite.enabled : false

---
"dedup struct field":
- skip:
features:
- headers
- do:
bulk:
index: test
refresh: true
body:
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/zap", "time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/zap", "time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/zap", "time": 2} } }'
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/zap", "time": 2} } }'
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/aap", "time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"message": "/e2e/h/aap", "time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"time": 1} } }'
- '{"index": {}}'
- '{"log": {"url": {"time": 2} } }'
- '{"index": {}}'
- '{"log": {"url": {"time": 2} } }'
- do:
headers:
Content-Type: 'application/json'
ppl:
body:
query: 'source=test | dedup log'
- match: {"total": 5}
Loading