stargate / data-api

JSON document API for Apache Cassandra (formerly known as JSON API)
https://stargate.io
Apache License 2.0
14 stars 16 forks source link

primaryKeySchema and corresponding Id-tuples from insertion are not ordered like CQL ((primary), clustering) #1720

Closed hemidactylus closed 1 week ago

hemidactylus commented 1 week ago

I am hitting what looks like a bug whereby the order of the insertedIds list of values returned from insertions, while corresponding to the primaryKeySchema, is not the same as the canonical CQL (<partition keys>), <clustering columns in the right order>)

  1. Create table
{
    "createTable": {
        "name": "table_all_returns",
        "definition": {
            "columns": {
                "p_ascii": {
                    "type": "ascii"
                },
                "p_bigint": {
                    "type": "bigint"
                },
                "p_blob": {
                    "type": "blob"
                },
                "p_boolean": {
                    "type": "boolean"
                },
                "p_date": {
                    "type": "date"
                },
                "p_decimal": {
                    "type": "decimal"
                },
                "p_double": {
                    "type": "double"
                },
                "p_double_minf": {
                    "type": "double"
                },
                "p_double_pinf": {
                    "type": "double"
                },
                "p_duration": {
                    "type": "duration"
                },
                "p_float": {
                    "type": "float"
                },
                "p_float_nan": {
                    "type": "float"
                },
                "p_inet": {
                    "type": "inet"
                },
                "p_int": {
                    "type": "int"
                },
                "p_list_int": {
                    "type": "list",
                    "valueType": "int"
                },
                "p_map_text_text": {
                    "keyType": "text",
                    "type": "map",
                    "valueType": "text"
                },
                "p_set_int": {
                    "type": "set",
                    "valueType": "int"
                },
                "p_smallint": {
                    "type": "smallint"
                },
                "p_text": {
                    "type": "text"
                },
                "p_text_nulled": {
                    "type": "text"
                },
                "p_text_omitted": {
                    "type": "text"
                },
                "p_time": {
                    "type": "time"
                },
                "p_timestamp": {
                    "type": "timestamp"
                },
                "p_uuid": {
                    "type": "uuid"
                },
                "p_vector": {
                    "dimension": 3,
                    "type": "vector"
                }
            },
            "primaryKey": {
                "partitionBy": [
                    "p_ascii",
                    "p_bigint"
                ],
                "partitionSort": {
                    "p_int": 1,
                    "p_boolean": -1
                }
            }
        }
    }
}

(response is ok: 1, no surprises)

  1. CQL describe (matching the provided above)
$> desc table table_all_returns ;

CREATE TABLE default_keyspace.table_all_returns (
    p_ascii ascii,
    p_bigint bigint,
    p_int int,
    p_boolean boolean,
    p_blob blob,
    p_date date,
    p_decimal decimal,
    p_double double,
    p_double_minf double,
    p_double_pinf double,
    p_duration duration,
    p_float float,
    p_float_nan float,
    p_inet inet,
    p_smallint smallint,
    p_text text,
    p_text_nulled text,
    p_text_omitted text,
    p_time time,
    p_timestamp timestamp,
    p_uuid uuid,
    p_vector vector<float, 3>,
    p_list_int list<int>,
    p_map_text_text map<text, text>,
    p_set_int set<int>,
    PRIMARY KEY ((p_ascii, p_bigint), p_int, p_boolean)
(etc etc...)
  1. an insertOne and its (weirdly-ordered) ID in the response
{
    "insertOne": {
        "document": {
            "p_bigint": 10000,
            "p_ascii": "abc",
            "p_boolean": false,
            "p_int": 987
        }
    }
}

And the response is (note the order in the list - which matches the primaryKeySchema all right, but is off w.r.t. CQL canonical order)

{
    "status": {
        "primaryKeySchema": {
            "p_ascii": {
                "type": "ascii"
            },
            "p_boolean": {
                "type": "boolean"
            },
            "p_int": {
                "type": "int"
            },
            "p_bigint": {
                "type": "bigint"
            }
        },
        "insertedIds": [
            [
                "abc",
                false,
                987,
                10000
            ]
        ]
    }
}