You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2018/07/12 21:04:01 UTC
[5/5] madlib git commit: Utilities: Add check for any array type
Utilities: Add check for any array type
Co-authored-by: Nikhil Kak <nk...@pivotal.io>
Closes #293
Project: http://git-wip-us.apache.org/repos/asf/madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/madlib/commit/a47cd1ff
Tree: http://git-wip-us.apache.org/repos/asf/madlib/tree/a47cd1ff
Diff: http://git-wip-us.apache.org/repos/asf/madlib/diff/a47cd1ff
Branch: refs/heads/master
Commit: a47cd1ff533a271e32470074986872e7bd278cbe
Parents: 11ecdc7
Author: Arvind Sridhar <ar...@berkeley.edu>
Authored: Mon Jul 9 16:14:48 2018 -0700
Committer: Rahul Iyer <ri...@apache.org>
Committed: Thu Jul 12 14:03:08 2018 -0700
----------------------------------------------------------------------
.../test/unit_tests/test_utilities.py_in | 3 +++
.../postgres/modules/utilities/utilities.py_in | 22 +++++++++++++-------
2 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/madlib/blob/a47cd1ff/src/ports/postgres/modules/utilities/test/unit_tests/test_utilities.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/utilities/test/unit_tests/test_utilities.py_in b/src/ports/postgres/modules/utilities/test/unit_tests/test_utilities.py_in
index 407a3c0..2d2c481 100644
--- a/src/ports/postgres/modules/utilities/test/unit_tests/test_utilities.py_in
+++ b/src/ports/postgres/modules/utilities/test/unit_tests/test_utilities.py_in
@@ -243,6 +243,9 @@ class UtilitiesTestCase(unittest.TestCase):
self.assertFalse(s.is_valid_psql_type('boolean[]', s.INCLUDE_ARRAY | s.ONLY_ARRAY))
self.assertFalse(s.is_valid_psql_type('boolean', s.ONLY_ARRAY))
self.assertFalse(s.is_valid_psql_type('boolean[]', s.ONLY_ARRAY))
+ self.assertTrue(s.is_valid_psql_type('boolean[]', s.ANY_ARRAY))
+ self.assertTrue(s.is_valid_psql_type('boolean[]', s.INTEGER | s.ANY_ARRAY))
+ self.assertFalse(s.is_valid_psql_type('boolean', s.ANY_ARRAY))
if __name__ == '__main__':
unittest.main()
http://git-wip-us.apache.org/repos/asf/madlib/blob/a47cd1ff/src/ports/postgres/modules/utilities/utilities.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/utilities/utilities.py_in b/src/ports/postgres/modules/utilities/utilities.py_in
index 55b6983..d571b40 100644
--- a/src/ports/postgres/modules/utilities/utilities.py_in
+++ b/src/ports/postgres/modules/utilities/utilities.py_in
@@ -175,34 +175,40 @@ TEXT = set(['text', 'varchar', 'character varying', 'char', 'character'])
BOOLEAN = set(['boolean'])
INCLUDE_ARRAY = set([unique_string('__include_array__')])
ONLY_ARRAY = set([unique_string('__only_array__')])
+ANY_ARRAY = set([unique_string('__any_array__')])
+
def is_valid_psql_type(arg, valid_types):
""" Verify if argument is a valid type
Args:
@param arg: str. Name of the Postgres type to validate
- @param valid_types: set. Set of type names to look into.
- This is typically created using the global types
- created in this module.
- Two non-type flags are provided:
+ @param valid_types: set. Set of valid type names to search.
+ This is typically created using the global names
+ in this module.
+ Three non-type flags are provided
+ (in descending order of precedence):
+ - ANY_ARRAY: check if arg is any array type
- ONLY_ARRAY: indicates that only array forms
of the valid types should be checked
- INCLUDE_ARRAY: indicates that array and scalar
forms of the valid types should be checked
- If both ONLY_ARRAY and INCLUDE_ARRAY are present,
- then ONLY_ARRAY takes precedence
-
Examples: 1. valid_types = BOOLEAN | INTEGER | TEXT
2. valid_types = BOOLEAN | INTEGER | ONLY_ARRAY
3. valid_types = NUMERIC | INCLUDE_ARRAY
"""
+ if not arg or not valid_types:
+ return False
+ if ANY_ARRAY <= valid_types:
+ return arg.rstrip().endswith('[]')
if ONLY_ARRAY <= valid_types:
- return ('[]' in arg and arg.rstrip('[]') in valid_types)
+ return (arg.rstrip().endswith('[]') and arg.rstrip('[] ') in valid_types)
if INCLUDE_ARRAY <= valid_types:
# Remove the [] from end of the arg type
# The single space is needed to ensure trailing white space is stripped
arg = arg.rstrip('[] ')
return (arg in valid_types)
+# ------------------------------------------------------------------------------
def is_psql_numeric_type(arg, exclude=None):