Skip to content
Permalink
Browse files
[NO ISSUE][FUN] extend object_concat to support an input array
- user model changes: no
- storage format changes: no
- interface changes: no

Details:
object_concat() should support an array of objects as
a signle input.

Change-Id: I2bf24229b5390106d06049c43af972734c6f9fd2
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/14404
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
  • Loading branch information
AliSolaiman committed Dec 9, 2021
1 parent 2871f73 commit 51981e629e394911b605078285b236254f437a6c
Show file tree
Hide file tree
Showing 23 changed files with 493 additions and 48 deletions.
@@ -125,6 +125,11 @@
<output-dir compare="Text">object_concat</output-dir>
</compilation-unit>
</test-case>
<test-case FilePath="objects">
<compilation-unit name="object_concat_with_array">
<output-dir compare="Text">object_concat_with_array</output-dir>
</compilation-unit>
</test-case>
<test-case FilePath="objects">
<compilation-unit name="object_length">
<output-dir compare="Text">object_length</output-dir>
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

SELECT VALUE
[
is_null(object_concat([])),
is_null(object_concat([null])),
is_missing(object_concat([missing])),
is_null(object_concat([{"a":1}, null])),
is_missing(object_concat([{"a":1}, null, missing])),
is_null(object_concat([{"a":1}, 1])),
is_null(object_concat([{"a":1}, []])),
object_concat([{"a":1, "b":"x"}]),
object_concat([{"a":1, "b":"x" }, {"c":true, "d":false}, {"e":null}] ),
object_concat([{"a":1, "b":"x", "c":true }, {"a":2, "b":"y" }, {"b":null}]),
object_concat([{"a":1, "b": { "x":2, "y":3 } }, {"a":10, "b": { "x":4, "y":5 } }, {"a":100}]),
object_concat([{"a":1, "b": { "x":2, "y":3 } }, {"a":10, "b": { "x":4, "y":5 } }, {"a":100, "b": { "x":400, "y":500 } }])
]
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

SELECT VALUE
object_concat((
SELECT VALUE object_add({}, i.id, i.label)
FROM [{"id":"test","label":"val"},{"id":"test2","label":"val1"}, {"id":"test2","label":"val2"}] i
))
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// test that object_concat() accepts and processes a single list of records argument
DROP DATAVERSE test IF EXISTS;
CREATE DATAVERSE test;
USE test;

CREATE TYPE flat_t AS {a: int, b: string};
CREATE TYPE nesting_t AS {x: {a: int, b: string}, y: [flat_t]};

CREATE TYPE t1 AS {id: int, array_nesting_rec: [nesting_t], array_flat_rec: [flat_t]};
CREATE DATASET ds(t1) PRIMARY KEY id;
@@ -0,0 +1,78 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

USE test;

INSERT INTO ds [
{"id": 1 ,"array_nesting_rec": [{"x": {"a": 3, "b": "3"}, "y": [{"a": 3, "b": "3"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]},
{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]}]
,"array_flat_rec": [{"a": 3, "b": "3"},
{"a": 2, "b": "2"},
{"a": 1, "b": "1"}]
,"optional_field1": [{"x": {"a": 3, "b": "3"}, "y": [{"a": 3, "b": "3"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]},
{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]}]
,"optional_field2": [{"a": 3, "b": "3"},
{"a": 2, "b": "2"},
{"a": 1, "b": "1"}]
},
{"id": 2 ,"array_nesting_rec": [{"x": {"a": 3, "b": "3"}, "y": [{"a": 3, "b": "3"}]},
{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]}]
,"array_flat_rec": [{"a": 3, "b": "3"},
{"a": 1, "b": "1"},
{"a": 2, "b": "2"}]
,"optional_field1": [{"x3": {"a": 3, "b": "3"}, "y3": [{"a": 3, "b": "3"}]},
{"x1": {"a": 1, "b": "1"}, "y1": [{"a": 1, "b": "1"}]},
{"x2": {"a": 2, "b": "2"}, "y2": [{"a": 2, "b": "2"}]}]
,"optional_field2": [1,
{"a": 1, "b": "1"},
"3"]
},
{"id": 3 ,"array_nesting_rec": [{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]},
{"x": {"a": 3, "b": "3"}, "y": [{"a": 3, "b": "3"}]}]
,"array_flat_rec": [{"a": 1, "b": "1"},
{"a": 2, "b": "2"},
{"a": 3, "b": "3"}]
,"optional_field1": 5
,"optional_field2": [{"x1": {"a": 1, "b": "1"}, "y1": [{"a": 1, "b": "1"}]},
{"x2": {"a": 2, "b": "2"}, "y2": [{"a": 2, "b": "2"}]},
{"x3": {"a": 3, "b": "3"}, "y3": [{"a": 3, "b": "3"}]}]
},
{"id": 4 ,"array_nesting_rec": [{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]},
{"x": {"a": 4, "b": "4"}, "y": [{"a": 4, "b": "4"}]}]
,"array_flat_rec": [{"a": 1, "b": "1"},
{"a": 2, "b": "2"},
{"a": 4, "b": "4"}]
,"optional_field1": {"x": {"a": 4, "b": "4"}, "y": [{"a": 4, "b": "4"}]}
,"optional_field2": {"a": 4, "b": "4"}
},
{"id": 5 ,"array_nesting_rec": [{"x": {"a": 1, "b": "1"}, "y": [{"a": 1, "b": "1"}]},
{"x": {"a": 2, "b": "2"}, "y": [{"a": 2, "b": "2"}]},
{"x": {"a": 5, "b": "5"}, "y": [{"a": 5, "b": "5"}]}]
,"array_flat_rec": [{"a": 1, "b": "1"},
{"a": 2, "b": "2"},
{"a": 5, "b": "5"}]
,"optional_field1": null
/*"optional_field2": missing*/
}
];
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE test;

FROM ds SELECT id, object_concat(array_nesting_rec) AS oc ORDER BY id;
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE test;

FROM ds SELECT id, object_concat(array_flat_rec) AS oc ORDER BY id;
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE test;

FROM ds SELECT id, object_concat(optional_field1) AS oc ORDER BY id;
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE test;

FROM ds SELECT id, object_concat(optional_field2) AS oc ORDER BY id;
@@ -0,0 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
USE test;

FROM ds SELECT id, object_concat(optional_field1, optional_field2) AS oc ORDER BY id;
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

DROP DATAVERSE test IF EXISTS;
@@ -0,0 +1 @@
[ true, true, true, true, true, true, true, { "a": 1, "b": "x" }, { "e": null, "c": true, "d": false, "a": 1, "b": "x" }, { "b": null, "a": 2, "c": true }, { "a": 100, "b": { "x": 4, "y": 5 } }, { "a": 100, "b": { "x": 400, "y": 500 } } ]
@@ -0,0 +1 @@
{ "test2": "val2", "test": "val" }
@@ -0,0 +1,5 @@
{ "id": 1, "oc": { "x": { "a": 1, "b": "1" }, "y": [ { "a": 1, "b": "1" } ] } }
{ "id": 2, "oc": { "x": { "a": 2, "b": "2" }, "y": [ { "a": 2, "b": "2" } ] } }
{ "id": 3, "oc": { "x": { "a": 3, "b": "3" }, "y": [ { "a": 3, "b": "3" } ] } }
{ "id": 4, "oc": { "x": { "a": 4, "b": "4" }, "y": [ { "a": 4, "b": "4" } ] } }
{ "id": 5, "oc": { "x": { "a": 5, "b": "5" }, "y": [ { "a": 5, "b": "5" } ] } }
@@ -0,0 +1,5 @@
{ "id": 1, "oc": { "a": 1, "b": "1" } }
{ "id": 2, "oc": { "a": 2, "b": "2" } }
{ "id": 3, "oc": { "a": 3, "b": "3" } }
{ "id": 4, "oc": { "a": 4, "b": "4" } }
{ "id": 5, "oc": { "a": 5, "b": "5" } }
@@ -0,0 +1,5 @@
{ "id": 1, "oc": { "x": { "a": 1, "b": "1" }, "y": [ { "a": 1, "b": "1" } ] } }
{ "id": 2, "oc": { "x2": { "a": 2, "b": "2" }, "y2": [ { "a": 2, "b": "2" } ], "x1": { "a": 1, "b": "1" }, "y1": [ { "a": 1, "b": "1" } ], "x3": { "a": 3, "b": "3" }, "y3": [ { "a": 3, "b": "3" } ] } }
{ "id": 3, "oc": null }
{ "id": 4, "oc": { "x": { "a": 4, "b": "4" }, "y": [ { "a": 4, "b": "4" } ] } }
{ "id": 5, "oc": null }
@@ -0,0 +1,5 @@
{ "id": 1, "oc": { "a": 1, "b": "1" } }
{ "id": 2, "oc": null }
{ "id": 3, "oc": { "x3": { "a": 3, "b": "3" }, "y3": [ { "a": 3, "b": "3" } ], "x2": { "a": 2, "b": "2" }, "y2": [ { "a": 2, "b": "2" } ], "x1": { "a": 1, "b": "1" }, "y1": [ { "a": 1, "b": "1" } ] } }
{ "id": 4, "oc": { "a": 4, "b": "4" } }
{ "id": 5 }
@@ -0,0 +1,5 @@
{ "id": 1, "oc": null }
{ "id": 2, "oc": null }
{ "id": 3, "oc": null }
{ "id": 4, "oc": { "a": 4, "b": "4", "x": { "a": 4, "b": "4" }, "y": [ { "a": 4, "b": "4" } ] } }
{ "id": 5 }
@@ -98,6 +98,10 @@ public ATypeTag getItemType(int itemOffset) {
}
}

public ATypeTag getItemTypeAt(int itemIndex) throws HyracksDataException {
return getItemType(getItemOffset(itemIndex));
}

public void writeItem(int itemIndex, DataOutput dos) throws IOException {
int itemOffset = getItemOffset(itemIndex);
int itemLength = getItemLength(itemOffset);
@@ -46,18 +46,20 @@ public IFunctionTypeInferer createFunctionTypeInferer() {
}
};

private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 2L;

private ARecordType[] argTypes;
private ARecordType listItemRecordType;

@Override
public void setImmutableStates(Object... states) {
argTypes = (ARecordType[]) states;
argTypes = (ARecordType[]) states[0];
listItemRecordType = (ARecordType) states[1];
}

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
return new RecordConcatEvalFactory(args, argTypes, false, sourceLoc);
return new RecordConcatEvalFactory(args, argTypes, listItemRecordType, false, sourceLoc);
}

@Override

0 comments on commit 51981e6

Please sign in to comment.