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

InsertMany with returnDocumentResponses flag enabled invalid input processing. #1670

Open
clun opened this issue Nov 8, 2024 · 1 comment
Labels
Bug Something isn't working To-Do

Comments

@clun
Copy link

clun commented Nov 8, 2024

Given the Table:

CREATE TABLE default_keyspace.table_composite_pk (
    id text,
    name text,
    age int,
    PRIMARY KEY ((id, name))
)

1. Default insertion

  • IN
{
  "insertMany": {
    "documents": [
      {
        "age": 22,
        "name": "John",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Sara",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Doctor",
        "id": "Silberman"
      }
    ],
    "options": {
      "ordered": false,
      "returnDocumentResponses": false
    }
  }
}
  • OUT
{
  "status": {
    "primaryKeySchema": {
      "name": {
        "type": "text"
      },
      "id": {
        "type": "text"
      }
    },
    "insertedIds": [
      [
        "John",
        "Connor"
      ],
      [
        "Sara",
        "Connor"
      ],
      [
        "Doctor",
        "Silberman"
      ]
    ]
  }
}

=> All good the insertedIds are populated

2. Default insertion with invalid input

Note

Notice the age provided as a string in the 3rd record

  • IN:
{
  "insertMany": {
    "documents": [
      {
        "age": 22,
        "name": "John",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Sara",
        "id": "Connor"
      },
      {
        "age": "50",  # <- error introduced on purpose
        "name": "Doctor",
        "id": "Silberman"
      }
    ],
    "options": {
      "ordered": false,
      "returnDocumentResponses": false
    }
  }
}
  • OUT
{
  "status": {
    "primaryKeySchema": {
      "name": {
        "type": "text"
      },
      "id": {
        "type": "text"
      }
    },
    "insertedIds": [
      [
        "John",
        "Connor"
      ],
      [
        "Sara",
        "Connor"
      ]
    ]
  },
  "errors": [
    {
      "stackTrace": [],
      "message": "Only values that are supported by the column data type can be included when inserting a document into a table.\n\nThe table default_keyspace.table_composite_pk defines the columns: id(text), name(text), age(int).\nThe request included the following columns that had values that are invalid: age: Error trying to convert to targetCQLType `INT` from value.class `java.lang.String`, value \"50\". Root cause: no codec matching value type.\n\nResend the request using only supported column values.",
      "errorCode": "INVALID_COLUMN_VALUES",
      "errorMessage": "(INVALID_COLUMN_VALUES) Only values that are supported by the column data type can be included when inserting a document into a table.\n\nThe table default_keyspace.table_composite_pk defines the columns: id(text), name(text), age(int).\nThe request included the following columns that had values that are invalid: age: Error trying to convert to targetCQLType `INT` from value.class `java.lang.String`, value \"50\". Root cause: no codec matching value type.\n\nResend the request using only supported column values.",
      "suppressed": [],
      "localizedMessage": "Only values that are supported by the column data type can be included when inserting a document into a table.\n\nThe table default_keyspace.table_composite_pk defines the columns: id(text), name(text), age(int).\nThe request included the following columns that had values that are invalid: age: Error trying to convert to targetCQLType `INT` from value.class `java.lang.String`, value \"50\". Root cause: no codec matching value type.\n\nResend the request using only supported column values."
    }
  ]
}

All good 2 insertedID and an explicit error.

3. Insertion with returnDocumentResponse flag

  • IN
{
  "insertMany": {
    "documents": [
      {
        "age": 22,
        "name": "John",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Sara",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Doctor",
        "id": "Silberman"
      }
    ],
    "options": {
      "ordered": false,
      "returnDocumentResponses": true
    }
  }
}
  • OUT:
{
  "status": {
    "primaryKeySchema": {
      "name": {
        "type": "text"
      },
      "id": {
        "type": "text"
      }
    },
    "documentResponses": [
      {
        "status": "OK",
        "_id": [
          "John",
          "Connor"
        ]
      },
      {
        "status": "OK",
        "_id": [
          "Sara",
          "Connor"
        ]
      },
      {
        "status": "OK",
        "_id": [
          "Doctor",
          "Silberman"
        ]
      }
    ]
  }
}

All good, you can notice out insertedids is empty replaced by documentResponses.

4. Insertion with returnDocumentResponse flag and invalid input

Note

We are trying to create errors in returnDocumentResponses to see a status KO of the shape of the output

IN:

{
  "insertMany": {
    "documents": [
      {
        "age": 22,
        "name": "John",
        "id": "Connor"
      },
      {
        "age": 50,
        "name": "Sara",
        "id": "Connor"
      },
      {
        "age": "50",       # <- error introduced on purpose
        "name": "Doctor",
        "id": "Silberman"
      }
    ],
    "options": {
      "ordered": false,
      "returnDocumentResponses": true
    }
  }
}

Out

💥

com.datastax.astra.client.exception.DataAPIException: [CLIENT_HTTP] - {"errors":[{"message":"Server failed: root cause: (java.util.NoSuchElementException) No value present","errorCode":"SERVER_UNHANDLED_ERROR"}]} (http:500)
@amorton
Copy link
Contributor

amorton commented Dec 11, 2024

Possible related to #1672

Fix that and then retest to see if we still get the problem,.

@amorton amorton added Bug Something isn't working To-Do labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working To-Do
Projects
None yet
Development

No branches or pull requests

2 participants