SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array and to_object CrateDB 4.2.7 及以上版本
SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array and to_object CrateDB 4.2.7 and upwards
将 Crate 版本 4.1.8
升级到 4.2.7
后,我在 CrateDB 中遇到以下错误
error during main processing: SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array(db_name.tbl_name."object_array_type_col_name")]
error : {
"message": "SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array(db_name.tbl_name."object_array_type_col_name")]",
"code": 4004
}
我正在尝试使用 INSERT INTO
和 CrateDB 中的 subsql 查询语句将数据从一个 table 移动到另一个 table 具有数据类型 OBJECT(DYNAMIC)
的列和 ARRAY(OBJECT(DYNAMIC))
并使用现有 table.
的原始架构创建临时 table
由于在原始 table 级别有一个 column_policy = 'dynamic'
,因此有几个动态添加的列具有相同的数据类型 OBJECT(DYNAMIC)
和 ARRAY(OBJECT(DYNAMIC))
.
下面是完整的 SQL 查询,我用它来移动在 Crate 版本 4.1.8
上工作正常的数据,并在版本 4.2.7
上引发上述异常。
INSERT INTO temp_tbl (col1, col2_object, col3_object_array, col4, col5, dynamic_col6_object, dynamic_col6_object_array) (SELECT col1, to_object(col2_object), to_object_array(col3_object_array), col4, col5, to_object(dynamic_col6_object), to_object_array(dynamic_col6_object_array) FROM original_tbl);
更新 1:
作为@proddata 的mentioned/pointed,我确实尝试了 CAST 但遇到以下错误
error: { "message": "SQLActionException[SQLParseException: The type 'object' of the insert source 'object_col_name' is not convertible to the type 'object' of target column 'object_col_name']", "code": 4000 }
to_object_array()
是一个内部/未记录的 CrateDB 函数,它在 4.2 及更高版本中是隐藏的
您可以尝试使用 <column> :: <type>
或 cast(<column> AS <type>)
代替吗。
例如
SELECT
[] :: ARRAY(OBJECT(DYNAMIC)),
cast([] AS ARRAY(OBJECT(DYNAMIC)))
另见https://crate.io/docs/crate/reference/en/4.6/general/ddl/data-types.html#cast
INSERT INTO temp_tbl (col1, col2_object, col3_object_array, col4, col5, dynamic_col6_object, dynamic_col6_object_array)
(SELECT
col1,
col2_object :: OBJECT,
col3_object_array :: ARRAY(OBJECT),
col4,
col5,
dynamic_col6_object :: OBJECT(DYNAMIC),
dynamic_col6_object_array :: ARRAY(OBJECT(DYNAMIC))
FROM original_tbl);
编辑:
对于某些 CrateDB 版本(可能介于 4.2.x - 4.5.1 之间)存在一个错误,如果目标列中的对象列,则阻止来自另一个 table 的对象的 INSERT
具有不同的对象属性,它们不是源对象列的超集。例如:
更完整的例子...
cr> CREATE TABLE dynamic_objects (
col1 TEXT
) WITH (column_policy = 'dynamic');
-- CREATE OK, 1 row affected (1.393 sec)
cr> INSERT INTO dynamic_objects (col1, obj_dyn, obj_arr_dyn) VALUES
('Hello', {a = 1}, [{x = 1},{y = 1}]);
-- INSERT OK, 1 row affected (0.216 sec)
cr> CREATE TABLE dynamic_objects_copy (
col1 TEXT
) WITH (column_policy = 'dynamic');
-- CREATE OK, 1 row affected (1.342 sec)
cr> INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn) VALUES
('Hello', {b = 1}, [{u = 1},{v = 1}]);
-- INSERT OK, 1 row affected (0.140 sec)
对于版本 4.2.7,以下查询失败:
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn, obj_arr_dyn FROM dynamic_objects;
已使用 4.2.7 进行测试(bug crate#11386
的解决方法
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn::TEXT::OBJECT, obj_arr_dyn::ARRAY(TEXT)::ARRAY(OBJECT) FROM dynamic_objects;
如果列已经存在:
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn::TEXT, obj_arr_dyn::ARRAY(TEXT) FROM dynamic_objects;
使用 4.6.3 测试(有效)
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn, obj_arr_dyn FROM dynamic_objects;
SELECT column_name, data_type FROM information_schema.columns
WHERE table_name = 'dynamic_objects_copy' AND column_name NOT LIKE '%[%';
+-------------+--------------+
| column_name | data_type |
+-------------+--------------+
| obj_arr_dyn | object_array |
| col1 | text |
| obj_dyn | object |
+-------------+--------------+
将 Crate 版本 4.1.8
升级到 4.2.7
error during main processing: SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array(db_name.tbl_name."object_array_type_col_name")]
error : {
"message": "SQLActionException[UnsupportedFeatureException: Unknown function: to_object_array(db_name.tbl_name."object_array_type_col_name")]",
"code": 4004
}
我正在尝试使用 INSERT INTO
和 CrateDB 中的 subsql 查询语句将数据从一个 table 移动到另一个 table 具有数据类型 OBJECT(DYNAMIC)
的列和 ARRAY(OBJECT(DYNAMIC))
并使用现有 table.
由于在原始 table 级别有一个 column_policy = 'dynamic'
,因此有几个动态添加的列具有相同的数据类型 OBJECT(DYNAMIC)
和 ARRAY(OBJECT(DYNAMIC))
.
下面是完整的 SQL 查询,我用它来移动在 Crate 版本 4.1.8
上工作正常的数据,并在版本 4.2.7
上引发上述异常。
INSERT INTO temp_tbl (col1, col2_object, col3_object_array, col4, col5, dynamic_col6_object, dynamic_col6_object_array) (SELECT col1, to_object(col2_object), to_object_array(col3_object_array), col4, col5, to_object(dynamic_col6_object), to_object_array(dynamic_col6_object_array) FROM original_tbl);
更新 1:
作为@proddata 的mentioned/pointed,我确实尝试了 CAST 但遇到以下错误
error: { "message": "SQLActionException[SQLParseException: The type 'object' of the insert source 'object_col_name' is not convertible to the type 'object' of target column 'object_col_name']", "code": 4000 }
to_object_array()
是一个内部/未记录的 CrateDB 函数,它在 4.2 及更高版本中是隐藏的
您可以尝试使用 <column> :: <type>
或 cast(<column> AS <type>)
代替吗。
例如
SELECT
[] :: ARRAY(OBJECT(DYNAMIC)),
cast([] AS ARRAY(OBJECT(DYNAMIC)))
另见https://crate.io/docs/crate/reference/en/4.6/general/ddl/data-types.html#cast
INSERT INTO temp_tbl (col1, col2_object, col3_object_array, col4, col5, dynamic_col6_object, dynamic_col6_object_array)
(SELECT
col1,
col2_object :: OBJECT,
col3_object_array :: ARRAY(OBJECT),
col4,
col5,
dynamic_col6_object :: OBJECT(DYNAMIC),
dynamic_col6_object_array :: ARRAY(OBJECT(DYNAMIC))
FROM original_tbl);
编辑:
对于某些 CrateDB 版本(可能介于 4.2.x - 4.5.1 之间)存在一个错误,如果目标列中的对象列,则阻止来自另一个 table 的对象的 INSERT
具有不同的对象属性,它们不是源对象列的超集。例如:
更完整的例子...
cr> CREATE TABLE dynamic_objects (
col1 TEXT
) WITH (column_policy = 'dynamic');
-- CREATE OK, 1 row affected (1.393 sec)
cr> INSERT INTO dynamic_objects (col1, obj_dyn, obj_arr_dyn) VALUES
('Hello', {a = 1}, [{x = 1},{y = 1}]);
-- INSERT OK, 1 row affected (0.216 sec)
cr> CREATE TABLE dynamic_objects_copy (
col1 TEXT
) WITH (column_policy = 'dynamic');
-- CREATE OK, 1 row affected (1.342 sec)
cr> INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn) VALUES
('Hello', {b = 1}, [{u = 1},{v = 1}]);
-- INSERT OK, 1 row affected (0.140 sec)
对于版本 4.2.7,以下查询失败:
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn, obj_arr_dyn FROM dynamic_objects;
已使用 4.2.7 进行测试(bug crate#11386
的解决方法INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn::TEXT::OBJECT, obj_arr_dyn::ARRAY(TEXT)::ARRAY(OBJECT) FROM dynamic_objects;
如果列已经存在:
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn::TEXT, obj_arr_dyn::ARRAY(TEXT) FROM dynamic_objects;
使用 4.6.3 测试(有效)
INSERT INTO dynamic_objects_copy (col1, obj_dyn, obj_arr_dyn)
SELECT col1, obj_dyn, obj_arr_dyn FROM dynamic_objects;
SELECT column_name, data_type FROM information_schema.columns
WHERE table_name = 'dynamic_objects_copy' AND column_name NOT LIKE '%[%';
+-------------+--------------+
| column_name | data_type |
+-------------+--------------+
| obj_arr_dyn | object_array |
| col1 | text |
| obj_dyn | object |
+-------------+--------------+