Skip to content

Commit

Permalink
[NO ISSUE][FUN] Implement array functions p1
Browse files Browse the repository at this point in the history
- user model changes: no
- storage format changes: no
- interface changes: no

details:
This is part of implementing array functions. This patch
includes array_insert(), array_append(), array_prepend()
array_put() and array_remove(). It includes re-organization
of those functions.

Change-Id: I7d9cb80325138daf99fb039793446d109481c94b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2751
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
  • Loading branch information
AliSolaiman authored and amoudi87 committed Jul 13, 2018
1 parent 2fff15a commit 0d7974f
Show file tree
Hide file tree
Showing 43 changed files with 1,495 additions and 163 deletions.
Expand Up @@ -50,9 +50,8 @@ public void test() throws Exception {
String className = func.getClass().getName();
// We test all generated functions except
// record and cast functions, which requires type settings.
String[] splits = className.split("\\.");
if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")
&& !splits[splits.length - 1].startsWith("Array")) {
if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")) {
System.out.println("Testing " + className);
testFunction(func);
++testedFunctions;
}
Expand Down Expand Up @@ -83,6 +82,10 @@ private void testFunction(IFunctionDescriptorFactory funcFactory) throws Excepti
int errorCode = Integer.parseInt(msg.substring(3, 7));
Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
continue;
} else if (msg.startsWith("HYR")) {
// Verifies the error code.
int errorCode = Integer.parseInt(msg.substring(3, 7));
Assert.assertTrue(errorCode >= 0 && errorCode < 1000);
} else {
// Any root-level data exceptions thrown from runtime functions should have an error code.
Assert.assertTrue(!(e instanceof HyracksDataException) || (e.getCause() != null));
Expand Down
Expand Up @@ -41,21 +41,17 @@

public class NullMissingTest {

private static final String arrayAppend = "ArrayAppendDescriptor";

@Test
public void test() throws Exception {
List<IFunctionDescriptorFactory> functions =
FunctionCollection.createDefaultFunctionCollection().getFunctionDescriptorFactories();
int testedFunctions = 0;
String[] splits;
for (IFunctionDescriptorFactory func : functions) {
String className = func.getClass().getName();
// We test all generated functions except
// record and cast functions, which requires type settings (we test them in runtime tests).
splits = className.split("\\.");
if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")
&& !splits[splits.length - 1].startsWith(arrayAppend)) {
if (className.contains("Gen") && !className.contains("record") && !className.contains("Cast")) {
System.out.println("Testing " + className);
testFunction(func);
++testedFunctions;
}
Expand Down
Expand Up @@ -22,10 +22,11 @@ use TinySocial;
{
"t1": (select array_append(t.`referred-topics`, "sth", 5) from TweetMessages t order by t.tweetid),
"t2": (select array_append([3, "John"], (select value v.compType from d1 v))),
"t3": (select array_append([3], 7, null, missing)),
"t4": (select array_append("non_array", 5)),
"t5": (select array_append("non_array", 5, missing)),
"t6": (select array_append([], 5, 10, 12.0, "sth")),
"t7": (select array_append(missing, 3, 9)),
"t8": (select array_append(null, 3, 9))
"t3": (array_append([3], 7, null, missing)), // missing
"t4": (array_append("non_array", 5)), // null
"t5": (array_append(null, 3, 9)), // null
"t6": (array_append("non_array", 5, missing)), // missing
"t7": (array_append([], 5, 10, 12.0, "sth")), // OK
"t8": (array_append(missing, 3, 9)), // missing
"t9": (array_append([3], 3, [9], null, "sth")) // OK to add nulls
};
@@ -0,0 +1,46 @@
/*
* 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 TinySocial if exists;
create dataverse TinySocial;

use TinySocial;


create type TinySocial.TwitterUserType as
{
`screen-name` : string,
lang : string,
friends_count : bigint,
statuses_count : bigint,
name : string,
followers_count : bigint
};

create type TinySocial.TweetMessageType as
closed {
tweetid : string,
user : TwitterUserType,
`sender-location` : point?,
`send-time` : datetime,
`referred-topics` : {{string}},
`message-text` : string
};

create dataset TweetMessages(TweetMessageType) primary key tweetid hints (`CARDINALITY`=`100`);
@@ -0,0 +1,22 @@
/*
* 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 TinySocial;

load dataset TweetMessages using localfs ((`path`=`asterix_nc1://data/tinysocial/twm.adm`),(`format`=`adm`));
@@ -0,0 +1,43 @@
/*
* 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 TinySocial;

{
"t1": (array_insert([1,2,3], 0, "a", "b")), // OK
"t2": (array_insert([1,2,3], 3, "a", "b")), // OK
"t3": (array_insert([1,1,2,4], 3, "a", "b")), // OK
"t4": (array_insert([1,1,2,4], 3, 7, "a", 7, "one more")), // OK
"t5": (array_insert([1,2,3], 4, "a")), // null, out of bound
"t6": (array_insert([1,2,3], -1, "a", "b")), // OK
"t7": (array_insert([1,2,3], -4, "a", "b")), // null, out of bound
"t8": (array_insert("non_array", 5, "val")), // null
"t9": (array_insert("non_array", 5, missing)), // missing
"t10": (array_insert([], 5, 10, 12.0, "sth")), // null, out of bound
"t11": (array_insert([], 0, 10, 12.0, "sth")), // OK
"t12": (array_insert([6], "a", 9)), // null, position non-numeric
"t13": (array_insert([6], 1.0, 9)), // OK
"t14": (array_insert([6], 1.5, 9)), // OK
"t15": (array_insert(null, 3, 9)), // null
"t16": (array_insert(missing, 3, 9)), // missing
"t17": (array_insert([6], 1, null, 9, null)), // OK to insert nulls
"t18": (array_insert([6], null, 5, 9, null)), // null
"t19": (array_insert([6], 3, null, missing, 9, null)), // missing
"t20": (select array_insert(t.`referred-topics`, 0, 5) from TweetMessages t order by t.tweetid)
};
@@ -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 TinySocial;
@@ -0,0 +1,56 @@
/*
* 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 TinySocial if exists;
create dataverse TinySocial;

use TinySocial;


create type TinySocial.TwitterUserType as
{
`screen-name` : string,
lang : string,
friends_count : bigint,
statuses_count : bigint,
name : string,
followers_count : bigint
};

create type TinySocial.TweetMessageType as
closed {
tweetid : string,
user : TwitterUserType,
`sender-location` : point?,
`send-time` : datetime,
`referred-topics` : {{string}},
`message-text` : string
};

create type t1 AS {

};

create type t2 AS {
id: int,
compType: t1
};

create dataset TweetMessages(TweetMessageType) primary key tweetid hints (`CARDINALITY`=`100`);
create dataset d1(t2) primary key id;
@@ -0,0 +1,27 @@
/*
* 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 TinySocial;

load dataset TweetMessages using localfs ((`path`=`asterix_nc1://data/tinysocial/twm.adm`),(`format`=`adm`));

insert into d1([
{"id":1, "compType":{"sth":33}},
{"id":2, "compType":{"sth":44}}
]);
@@ -0,0 +1,32 @@
/*
* 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 TinySocial;

{
"t1": (select array_prepend("sth", 5, t.`referred-topics`) from TweetMessages t order by t.tweetid),
"t2": (select array_prepend((select value v.compType from d1 v), [3, "John"])),
"t3": (array_prepend(7, null, missing, [3])), // missing
"t4": (array_prepend(5, "non_array")), // null
"t5": (array_prepend(3, 9, null)), // null
"t6": (array_prepend(5, missing, "non_array")), // missing
"t7": (array_prepend(5, 10, 12.0, "sth",[77, "val"])), // OK
"t8": (array_prepend(5, 10, null, "sth",[77, "val"])), // OK to insert nulls
"t9": (array_prepend(3, 9, missing)) // missing
};
@@ -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 TinySocial;

0 comments on commit 0d7974f

Please sign in to comment.