This is an automated email from the ASF dual-hosted git repository. htowaileb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
View the commit online: https://github.com/apache/asterixdb/commit/38649da1540859feb5406c85734ee1fe7548e452 The following commit(s) were added to refs/heads/master by this push: new 38649da [NO ISSUE] Make type computer more generic 38649da is described below commit 38649da1540859feb5406c85734ee1fe7548e452 Author: Hussain Towaileb <[email protected]> AuthorDate: Wed Nov 20 22:26:09 2019 +0300 [NO ISSUE] Make type computer more generic - user model changes: no - storage format changes: no - interface changes: no Details: - Converted a type computer to be more genericly behaving, now it can be reused by multiple functions instead of creating a different type computer for each function. Change-Id: I3027376e8523657d30257eec542cb53766c835cd Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/4183 Reviewed-by: Hussain Towaileb <[email protected]> Reviewed-by: Dmitry Lychagin <[email protected]> Contrib: Jenkins <[email protected]> Tested-by: Jenkins <[email protected]> Integration-Tests: Jenkins <[email protected]> --- .../asterix/om/functions/BuiltinFunctions.java | 69 ++++++++++------------ .../impl/AbstractStringTypeComputer.java | 40 ------------- .../impl/StringBooleanTypeComputer.java | 39 ------------ .../typecomputer/impl/StringInt32TypeComputer.java | 40 ------------- .../impl/StringStringTypeComputer.java | 39 ------------ .../impl/StringToInt64ListTypeComputer.java | 42 ------------- .../impl/StringToStringListTypeComputer.java | 42 ------------- .../impl/UnaryStringInt64TypeComputer.java | 40 ------------- .../impl/UniformInputTypeComputer.java | 68 +++++++++++++++++++++ 9 files changed, 100 insertions(+), 319 deletions(-) diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java index 0459195..b6c1bf4 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/functions/BuiltinFunctions.java @@ -125,12 +125,7 @@ import org.apache.asterix.om.typecomputer.impl.RecordRemoveFieldsTypeComputer; import org.apache.asterix.om.typecomputer.impl.ScalarArrayAggTypeComputer; import org.apache.asterix.om.typecomputer.impl.ScalarVersionOfAggregateResultType; import org.apache.asterix.om.typecomputer.impl.SleepTypeComputer; -import org.apache.asterix.om.typecomputer.impl.StringBooleanTypeComputer; -import org.apache.asterix.om.typecomputer.impl.StringInt32TypeComputer; import org.apache.asterix.om.typecomputer.impl.StringJoinTypeComputer; -import org.apache.asterix.om.typecomputer.impl.StringStringTypeComputer; -import org.apache.asterix.om.typecomputer.impl.StringToInt64ListTypeComputer; -import org.apache.asterix.om.typecomputer.impl.StringToStringListTypeComputer; import org.apache.asterix.om.typecomputer.impl.SubsetCollectionTypeComputer; import org.apache.asterix.om.typecomputer.impl.SubstringTypeComputer; import org.apache.asterix.om.typecomputer.impl.SwitchCaseComputer; @@ -142,7 +137,7 @@ import org.apache.asterix.om.typecomputer.impl.ToObjectTypeComputer; import org.apache.asterix.om.typecomputer.impl.TreatAsTypeComputer; import org.apache.asterix.om.typecomputer.impl.UnaryBinaryInt64TypeComputer; import org.apache.asterix.om.typecomputer.impl.UnaryMinusTypeComputer; -import org.apache.asterix.om.typecomputer.impl.UnaryStringInt64TypeComputer; +import org.apache.asterix.om.typecomputer.impl.UniformInputTypeComputer; import org.apache.asterix.om.typecomputer.impl.UnorderedListConstructorTypeComputer; import org.apache.asterix.om.types.hierachy.ATypeHierarchy; import org.apache.commons.lang3.mutable.Mutable; @@ -1716,47 +1711,47 @@ public class BuiltinFunctions { // string functions addFunction(STRING_CONSTRUCTOR, AStringTypeComputer.INSTANCE, true); // TODO addFunction(STRING_LIKE, BooleanFunctionTypeComputer.INSTANCE, true); - addFunction(STRING_CONTAINS, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_TO_CODEPOINT, StringToInt64ListTypeComputer.INSTANCE, true); + addFunction(STRING_CONTAINS, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_TO_CODEPOINT, UniformInputTypeComputer.STRING_INT64_LIST_INSTANCE, true); addFunction(CODEPOINT_TO_STRING, AStringTypeComputer.INSTANCE, true); // TODO addFunction(STRING_CONCAT, ConcatTypeComputer.INSTANCE_STRING, true); // TODO addFunction(SUBSTRING, SubstringTypeComputer.INSTANCE, true); // TODO addFunction(SUBSTRING_OFFSET_1, SubstringTypeComputer.INSTANCE, true); // TODO addFunction(SUBSTRING2, AStringTypeComputer.INSTANCE_NULLABLE, true); addFunction(SUBSTRING2_OFFSET_1, AStringTypeComputer.INSTANCE_NULLABLE, true); - addFunction(STRING_LENGTH, UnaryStringInt64TypeComputer.INSTANCE, true); - addFunction(STRING_LOWERCASE, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_UPPERCASE, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_INITCAP, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_TRIM, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_LTRIM, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_RTRIM, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_TRIM2, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_LTRIM2, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_RTRIM2, StringStringTypeComputer.INSTANCE, true); - addFunction(STRING_POSITION, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_POSITION_OFFSET_1, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_STARTS_WITH, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_ENDS_WITH, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_MATCHES, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_MATCHES_WITH_FLAG, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_LIKE, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_LIKE_WITH_FLAG, StringBooleanTypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_POSITION, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_POSITION_OFFSET_1, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_POSITION_WITH_FLAG, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_POSITION_OFFSET_1_WITH_FLAG, StringInt32TypeComputer.INSTANCE, true); - addFunction(STRING_REGEXP_REPLACE, StringStringTypeComputer.INSTANCE, true); + addFunction(STRING_LENGTH, UniformInputTypeComputer.STRING_INT64_INSTANCE, true); + addFunction(STRING_LOWERCASE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_UPPERCASE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_INITCAP, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_TRIM, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_LTRIM, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_RTRIM, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_TRIM2, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_LTRIM2, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_RTRIM2, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(STRING_POSITION, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_POSITION_OFFSET_1, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_STARTS_WITH, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_ENDS_WITH, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_MATCHES, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_MATCHES_WITH_FLAG, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_REGEXP_LIKE, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_REGEXP_LIKE_WITH_FLAG, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); + addFunction(STRING_REGEXP_POSITION, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_REGEXP_POSITION_OFFSET_1, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_REGEXP_POSITION_WITH_FLAG, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_REGEXP_POSITION_OFFSET_1_WITH_FLAG, UniformInputTypeComputer.STRING_INT32_INSTANCE, true); + addFunction(STRING_REGEXP_REPLACE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); addFunction(STRING_REGEXP_REPLACE_WITH_FLAG, AStringTypeComputer.INSTANCE_NULLABLE, true); - addFunction(STRING_REPLACE, StringStringTypeComputer.INSTANCE, true); + addFunction(STRING_REPLACE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); addFunction(STRING_REPLACE_WITH_LIMIT, AStringTypeComputer.INSTANCE_NULLABLE, true); - addFunction(STRING_REVERSE, StringStringTypeComputer.INSTANCE, true); - addFunction(SUBSTRING_BEFORE, StringStringTypeComputer.INSTANCE, true); - addFunction(SUBSTRING_AFTER, StringStringTypeComputer.INSTANCE, true); - addPrivateFunction(STRING_EQUAL, StringBooleanTypeComputer.INSTANCE, true); + addFunction(STRING_REVERSE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(SUBSTRING_BEFORE, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addFunction(SUBSTRING_AFTER, UniformInputTypeComputer.STRING_STRING_INSTANCE, true); + addPrivateFunction(STRING_EQUAL, UniformInputTypeComputer.STRING_BOOLEAN_INSTANCE, true); addFunction(STRING_JOIN, StringJoinTypeComputer.INSTANCE, true); addFunction(STRING_REPEAT, AStringTypeComputer.INSTANCE_NULLABLE, true); - addFunction(STRING_SPLIT, StringToStringListTypeComputer.INSTANCE, true); + addFunction(STRING_SPLIT, UniformInputTypeComputer.STRING_STRING_LIST_INSTANCE, true); addPrivateFunction(ORDERED_LIST_CONSTRUCTOR, OrderedListConstructorTypeComputer.INSTANCE, true); addFunction(POINT_CONSTRUCTOR, APointTypeComputer.INSTANCE, true); diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java deleted file mode 100644 index ba7fc65..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/AbstractStringTypeComputer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer; -import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.AUnionType; -import org.apache.asterix.om.types.IAType; - -/** - * For function signature: nullable_return_type fun(string...) - */ -public abstract class AbstractStringTypeComputer extends AbstractResultTypeComputer { - - protected static IAType getType(IAType returnType, IAType... argsTypes) { - // all args are expected to be strings. If any arg is not string (ANY or mismatched-type), return nullable - for (IAType actualType : argsTypes) { - if (actualType.getTypeTag() != ATypeTag.STRING) { - return AUnionType.createNullableType(returnType); - } - } - return returnType; - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringBooleanTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringBooleanTypeComputer.java deleted file mode 100644 index 032b7be..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringBooleanTypeComputer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable_boolean fun(string...) - */ -public class StringBooleanTypeComputer extends AbstractStringTypeComputer { - public static final StringBooleanTypeComputer INSTANCE = new StringBooleanTypeComputer(); - - private StringBooleanTypeComputer() { - } - - @Override - public IAType getResultType(ILogicalExpression expr, IAType... types) throws AlgebricksException { - return getType(BuiltinType.ABOOLEAN, types); - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringInt32TypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringInt32TypeComputer.java deleted file mode 100644 index 8f888e2..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringInt32TypeComputer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable_int32 fun(string...) - */ -public class StringInt32TypeComputer extends AbstractStringTypeComputer { - public static final StringInt32TypeComputer INSTANCE = new StringInt32TypeComputer(); - - private StringInt32TypeComputer() { - } - - @Override - public IAType getResultType(ILogicalExpression expr, IAType... types) throws AlgebricksException { - return getType(BuiltinType.AINT32, types); - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringStringTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringStringTypeComputer.java deleted file mode 100644 index cb9ec8e..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringStringTypeComputer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable_string fun(string...) - */ -public class StringStringTypeComputer extends AbstractStringTypeComputer { - public static final StringStringTypeComputer INSTANCE = new StringStringTypeComputer(); - - private StringStringTypeComputer() { - } - - @Override - public IAType getResultType(ILogicalExpression expr, IAType... inputTypes) throws AlgebricksException { - return getType(BuiltinType.ASTRING, inputTypes); - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToInt64ListTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToInt64ListTypeComputer.java deleted file mode 100644 index e138d44..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToInt64ListTypeComputer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.AOrderedListType; -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable[int64] fun(string...) - */ -public class StringToInt64ListTypeComputer extends AbstractStringTypeComputer { - - public static final StringToInt64ListTypeComputer INSTANCE = new StringToInt64ListTypeComputer(); - - private StringToInt64ListTypeComputer() { - } - - @Override - protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { - return getType(new AOrderedListType(BuiltinType.AINT64, null), strippedInputTypes); - } -} \ No newline at end of file diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToStringListTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToStringListTypeComputer.java deleted file mode 100644 index 66dfe09..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/StringToStringListTypeComputer.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ - -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.AOrderedListType; -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable[string] fun(string...) - */ -public class StringToStringListTypeComputer extends AbstractStringTypeComputer { - - public static final StringToStringListTypeComputer INSTANCE = new StringToStringListTypeComputer(); - - private StringToStringListTypeComputer() { - } - - @Override - protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { - return getType(new AOrderedListType(BuiltinType.ASTRING, null), strippedInputTypes); - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64TypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64TypeComputer.java deleted file mode 100644 index 13079e2..0000000 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UnaryStringInt64TypeComputer.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ -package org.apache.asterix.om.typecomputer.impl; - -import org.apache.asterix.om.types.BuiltinType; -import org.apache.asterix.om.types.IAType; -import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; -import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; - -/** - * For function signature: nullable_int64 fun(string) - */ -public class UnaryStringInt64TypeComputer extends AbstractStringTypeComputer { - - public static final UnaryStringInt64TypeComputer INSTANCE = new UnaryStringInt64TypeComputer(); - - private UnaryStringInt64TypeComputer() { - } - - @Override - public IAType getResultType(ILogicalExpression expr, IAType... types) throws AlgebricksException { - return getType(BuiltinType.AINT64, types); - } -} diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UniformInputTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UniformInputTypeComputer.java new file mode 100644 index 0000000..dc218e2 --- /dev/null +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/UniformInputTypeComputer.java @@ -0,0 +1,68 @@ +/* + * 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. + */ +package org.apache.asterix.om.typecomputer.impl; + +import org.apache.asterix.om.typecomputer.base.AbstractResultTypeComputer; +import org.apache.asterix.om.types.AOrderedListType; +import org.apache.asterix.om.types.ATypeTag; +import org.apache.asterix.om.types.BuiltinType; +import org.apache.asterix.om.types.IAType; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression; + +/** + * This type computer functions based on 2 arguments, the {@code inputType} and the {@code outputType}. It checks that + * all the input types conform to the provided {@code inputType}, and if so, it returns the {@code outputType}, + * otherwise null type is returned. + */ +public class UniformInputTypeComputer extends AbstractResultTypeComputer { + + public static final UniformInputTypeComputer STRING_STRING_INSTANCE = + new UniformInputTypeComputer(BuiltinType.ASTRING, BuiltinType.ASTRING); + public static final UniformInputTypeComputer STRING_BOOLEAN_INSTANCE = + new UniformInputTypeComputer(BuiltinType.ASTRING, BuiltinType.ABOOLEAN); + public static final UniformInputTypeComputer STRING_INT32_INSTANCE = + new UniformInputTypeComputer(BuiltinType.ASTRING, BuiltinType.AINT32); + public static final UniformInputTypeComputer STRING_INT64_INSTANCE = + new UniformInputTypeComputer(BuiltinType.ASTRING, BuiltinType.AINT64); + public static final UniformInputTypeComputer STRING_STRING_LIST_INSTANCE = new UniformInputTypeComputer( + BuiltinType.ASTRING, new AOrderedListType(BuiltinType.ASTRING, BuiltinType.ASTRING.getTypeName())); + public static final UniformInputTypeComputer STRING_INT64_LIST_INSTANCE = new UniformInputTypeComputer( + BuiltinType.ASTRING, new AOrderedListType(BuiltinType.AINT64, BuiltinType.AINT64.getTypeName())); + + private final IAType inputType; + private final IAType outputType; + + private UniformInputTypeComputer(IAType inputType, IAType outputType) { + this.inputType = inputType; + this.outputType = outputType; + } + + @Override + public IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException { + // all args are expected to be of type inputType + for (IAType actualType : strippedInputTypes) { + if (actualType.getTypeTag() != inputType.getTypeTag() && actualType.getTypeTag() != ATypeTag.ANY) { + return BuiltinType.ANULL; + } + } + + return outputType; + } +}
