-
Notifications
You must be signed in to change notification settings - Fork 50
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
Typed Arrays #147
Comments
As of PR #214, we switched to untyped arrays in the API spec for values returned in query responses. While this works, it can be improved: we may want to consider using typed arrays again. The array type in the spec will probably have to be the sum type |
Stale issue message |
Hi @chicco785, I would like to contribute on this issue. Please assign it to me. |
hi @Ajaysamdyan, the thing may be a bit tricky to handle without messing up also sql_translator, but not impacting it would be the best option I think. |
Hi @c0c0n3 , thanks for sharing the details and guidance. As per my primary investigation on cratedb, i have tested and verify that cratedb support the insertion of array object of different type like: text, Boolean, number etc. I have executed the below mentioned some queries for verification: CREATE TABLE my_table_arrays ( tags array(text), objects array(object as (age integer, name text))); Here, data is successfully stored into the database. So kindly let me know, is my investigation going in right direction ? |
Hi @Ajaysamdyan, that's great, you're definitely heading in the right direction. One thing to consider is that my comments are ancient and probably only applicable to Crate 3 which we don't support anymore. Do new versions of Crate support inserting and then querying an arbitrary JSON array? If so then, we don't need the typed approach anymore. In other words, would this work with a recent version of Crate
and if does, then how can you query column The reason why I'm mentioning this is that it'd simplify the Python implementation.... |
Hi @c0c0n3 , Please find the major blue points supported by latest crateDB version;
So, currently inserting and casting of a json object array of different type is not supported by crateDB. I had tested and verified it. kindly suggest me a way to proceed. |
Hi @Ajaysamdyan, thanks for sharing your findings. I think I might've found a workaround that could let us store JSON arrays in Crate---tested with version 4.5.1. Here's a sum up. To recap, here's a pseudo JSON (sum) type definition
Notice the recursive definition of array [1, 2] -- a homogeneous-type array: all numbers
["yo!", true] -- a mixed-type array: strings and booleans
[{"k": 1}, 2] -- a mixed-type array: objects and numbers
-- a more complex mixed-type array: string, array with a string and a bool, number
["wada", ["wada", false], 3] The problem is that is seems Crate doesn't support mixed-type arrays. So while Crate will swallow the first array without a hiccup, it'll moan about the others---to be honest, I think for good reasons, but my opinion is irrelevant here. What to do then? We know Crate supports JSON-like objects, so we might be able to encode a JSON array into an object. The mapping could be like this (pseudo-code)
Like I said earlier, I've given this a try with Crate 4.5.1 and it seems to work for the most part but there are some corner cases we need to look into and some design issues to consider. Here's my test. CREATE TABLE t (an_array_attr OBJECT(ignored)); INSERT INTO t (an_array_attr) VALUES ( '{"value": [1, 2]}'::object );
INSERT INTO t (an_array_attr) VALUES ( '{"value": ["yo!", true]}'::object );
INSERT INTO t (an_array_attr) VALUES ( '{"value": [{"k": 1}, 2]}'::object );
INSERT INTO t (an_array_attr) VALUES ( '{"value": ["wada", ["wada", false], 3]}'::object ); While all these inserts worked without a glitch, there still are things to consider which might make this solution unfeasible.
|
Hi @c0c0n3, Thanks for sharing the test cases, I have also performed this test and observed the same behavior of cratedb. Please find the below mentioned test case of dynamic insertion:
Homogeneous Type:
Mixed_Array Type:
Here, a new table t3 created using same dynamic insertion. It seems that Moreover, I have also asked the |
Hi @Ajaysamdyan, that's brilliant, thanks for this and thanks for asking the Crate community about mixed-type support. Let's wait to see what the answer is and then we'll take it from there. |
Hi @c0c0n3 , As per the discussion with
|
Hi @Ajaysamdyan
Ha! I actually tested the queries through the admin UI too and just assumed the data wasn't there. Glad it's just a display issue and the data doesn't actually get zapped :-) Unless @chicco785 has anything on the contrary, we could go ahead with the implementation I suppose? |
Hi there, the CrateDB 4.6.4 hotfix release will include Admin UI 1.19.2, which includes the fix crate/crate-admin#745 by @proddata - thanks a stack! The Docker image is already available through With kind regards, |
@c0c0n3 Is this still under active development? According to Crate-Docs: https://cratedb.com/docs/crate/reference/en/4.8/general/ddl/data-types.html#type-object |
@tstorek nope, it hasn't been implemented yet... |
With #142 we introduced better support for saving structured values as objects in Crate.
We should probably extend that line of work to include support for arrays of structured values, which should be saved as arrays of objects in Crate.
But as we are at it, why not consider typed arrays? Currently we support conversion from the following NGSI attribute types:
Boolean
,Number
,Integer
,Text
,DateTime
,ISO8601
,geo:json
,geo:point
,StructuredValue
. But when it comes to arrays, we convert array elements to strings so we only support storing arrays of strings in Crate. It'd be nice if we could support arrays of all the above types---i.e.array[bool]
,array[float]
,array[object]
, etc.See also: #36, #24.
The text was updated successfully, but these errors were encountered: