Skip to content
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

Allow passing of empty JSON Object ({ }) for sort for find and findOne Commands #572

Closed
tatu-at-datastax opened this issue Oct 20, 2023 · 5 comments · Fixed by #576
Closed
Assignees

Comments

@tatu-at-datastax
Copy link
Contributor

tatu-at-datastax commented Oct 20, 2023

(reported by user)

Looks like passing an "empty" sort argument (as opposed to passing nothing, or null) to find and/or findOne Command leads to an exception. It should instead be handled same as missing/null value.

@tatu-at-datastax tatu-at-datastax self-assigned this Oct 20, 2023
@tatu-at-datastax
Copy link
Contributor Author

@jeffreyscarpenter suggested we might want to error out instead; noting for now. Will start by first adding a test to see what happens currently; can decide on right action to take later today.

@tatu-at-datastax tatu-at-datastax changed the title Allow passing of empty JSON Object ({ }) for sort for find Command Allow passing of empty JSON Object ({ }) for sort for findOne Command Oct 20, 2023
@tatu-at-datastax
Copy link
Contributor Author

Odd: neither find() nor findOne() seem to fail on empty Object for sort. Will check in integration tests to verify they are ok but wondering if failure requires something else.

@hemidactylus
Copy link
Contributor

I am copying the code blocks that make for a reproducible example. In my experience, findOne always works and find gives an error when sort: {} is added to the payload, while working as expected with that part left out altogether.

setup

export ASTRA_DB_ID="4f835778..."
export ASTRA_DB_APPLICATION_TOKEN="AstraCS:..."
export NAMESPACE="vectorapi"
export ASTRA_DB_REGION="us-east1"


curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}" \
  -d '{"createCollection": {"name": "v_test_find", "options" : {"vector" : {"size" : 5, "function" : "cosine"}}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"


curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"insertOne": {"document": {"_id": "4","name": "Coded Cleats","description": "ChatGPT integrated sneakers that talk to you","$vector": [0.25, 0.25, 0.25, 0.25, 0.25]}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"

working finds

curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"find": {"filter": {"name": "Coded Cleats"}, "projection": {}, "options": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"
# all right:
#   {"data":{"documents":[{"_id":"4","name":"Coded Cleats","description":"ChatGPT integrated sneakers that talk to you","$vector":[0.25,0.25,0.25,0.25,0.25]}],"nextPageState":null}}

curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"find": {"filter": {}, "projection": {}, "options": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"
# all right:
#   {"data":{"documents":[{"_id":"4","name":"Coded Cleats","description":"ChatGPT integrated sneakers that talk to you","$vector":[0.25,0.25,0.25,0.25,0.25]}],"nextPageState":null}}

faulty finds

curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"find": {"filter": {"name": "Coded Cleats"}, "projection": {}, "options": {}, "sort": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"
# {"details":"Error id ...","stack":""}


curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"find": {"filter": {}, "projection": {}, "options": {}, "sort": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"
# {"details":"Error id ...","stack":""}

all-working findOnes

curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"findOne": {"filter": {"name": "Coded Cleats"}, "projection": {}, "options": {}, "sort": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"


curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"findOne": {"filter": {}, "projection": {}, "options": {}, "sort": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"


curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"findOne": {"filter": {"name": "Coded Cleats"}, "projection": {}, "options": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"

curl -XPOST \
  "https://${ASTRA_DB_ID}-${ASTRA_DB_REGION}.apps.astra.datastax.com/api/json/v1/${NAMESPACE}/v_test_find" \
  -d '{"findOne": {"filter": {}, "projection": {}, "options": {}}}' \
  -H "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
  -H "Content-Type: application/json"

tatu-at-datastax added a commit that referenced this issue Oct 23, 2023
@tatu-at-datastax
Copy link
Contributor Author

Thank you @hemidactylus -- that should allow reproduction; either with empty filter or empty options or perhaps both. Or could be filter on non-doc-id field too.

@tatu-at-datastax tatu-at-datastax changed the title Allow passing of empty JSON Object ({ }) for sort for findOne Command Allow passing of empty JSON Object ({ }) for sort for find and findOne Commands Oct 23, 2023
@tatu-at-datastax
Copy link
Contributor Author

Ok can reproduce and have a simple fix I think, see #576 .

tatu-at-datastax added a commit that referenced this issue Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants