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

Unsupported column data type when trying to insert a map value #1747

Open vkarpov15 opened 1 day ago

vkarpov15 commented 1 day ago

Running data-api v1.0.20 locally, I created an orders table as follows:

{
      createTable: {
        name: 'orders',
        definition: {
          primaryKey: '_id',
          columns: {
            _id: { type: 'text' },
            total: { type: 'decimal' },
            name: { type: 'text' },
            paymentMethod: { type: 'map', keyType: 'text', valueType: 'text' },
            items: { type: 'list', valueType: 'text' }
          }
        }
      }
    }

When I try to run the following insertOne:

{
  "insertOne": {
    "document": {
      "items": [
        "{\"productId\":\"673e4cc615d317995d5ceb12\",\"quantity\":1}"
      ],
      "total": 799,
      "name": "Stripe Test",
      "paymentMethod": {
        "id": "test-stripe-payment-method-id",
        "brand": "visa",
        "last4": "0000"
      },
      "_id": "673e4d76aedcce42399ec417"
    }
  }
}

I get back:

Command "insertOne" failed with the following errors: [{"message":"Only supported column types can be included when inserting a document into a table.\n\nThe table demo.orders defines the columns: \"_id\"(text), items(list<text>), name(text), \"paymentMethod\"(map<text, text>), total(decimal).\nThe request included the following columns that have unsupported data types: \"paymentMethod\"(map<text, text>).\n\nResend the request using only supported column types.","errorCode":"UNSUPPORTED_COLUMN_TYPES"}]

Am I doing something wrong here?

Hazel-Datastax commented 16 hours ago

@vkarpov15 I cannot reproduce your error, here is the command I tried in Postman, and I just reformat your content. Could you double-check if it's the thing you want? Create Table:

{
    "createTable": {
        "name": "orders",
        "definition": {
            "primaryKey": "_id",
            "columns": {
                "_id": {
                    "type": "text"
                },
                "total": {
                    "type": "decimal"
                },
                "name": {
                    "type": "text"
                },
                "paymentMethod": {
                    "type": "map",
                    "keyType": "text",
                    "valueType": "text"
                },
                "items": {
                    "type": "list",
                    "valueType": "text"
                }
            }
        }
    }
}

Insert one:

{
  "insertOne": {
    "document": {
      "items": [
        "{\"productId\":\"673e4cc615d317995d5ceb12\",\"quantity\":1}"
      ],
      "total": 799,
      "name": "Stripe Test",
      "paymentMethod": {
        "id": "test-stripe-payment-method-id",
        "brand": "visa",
        "last4": "0000"
      },
      "_id": "673e4d76aedcce42399ec417"
    }
  }
}

Result from insert one:

{
    "status": {
        "primaryKeySchema": {
            "_id": {
                "type": "text"
            }
        },
        "insertedIds": [
            [
                "673e4d76aedcce42399ec417"
            ]
        ]
    }
}