Build: Add single quote while setting AppendOnly guc

JIRA: MADLIB-1273

Commit 3db98babe3326fb5e2cd16d0639a2bef264f4b04 added a context manager
for setting appendonly to false for all madlib modules. The commit was
missing a quote around the `gp_default_storage_options` guc because of
which the set command always failed. This commit adds a quote while
setting the guc.

Co-authored-by: Nikhil Kak <[email protected]>

Closes #323


Project: http://git-wip-us.apache.org/repos/asf/madlib/repo
Commit: http://git-wip-us.apache.org/repos/asf/madlib/commit/03e82bc5
Tree: http://git-wip-us.apache.org/repos/asf/madlib/tree/03e82bc5
Diff: http://git-wip-us.apache.org/repos/asf/madlib/diff/03e82bc5

Branch: refs/heads/master
Commit: 03e82bc50494367c6b65dced66cf0042b3060042
Parents: d7d54b9
Author: Jingyi Mei <[email protected]>
Authored: Wed Sep 26 13:56:04 2018 -0700
Committer: Jingyi Mei <[email protected]>
Committed: Wed Sep 26 14:02:49 2018 -0700

----------------------------------------------------------------------
 .../postgres/modules/utilities/control.py_in    | 20 +++++++++++++-------
 .../test/unit_tests/test_control.py_in          |  8 ++++----
 2 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/madlib/blob/03e82bc5/src/ports/postgres/modules/utilities/control.py_in
----------------------------------------------------------------------
diff --git a/src/ports/postgres/modules/utilities/control.py_in 
b/src/ports/postgres/modules/utilities/control.py_in
index d147103..13b22f0 100644
--- a/src/ports/postgres/modules/utilities/control.py_in
+++ b/src/ports/postgres/modules/utilities/control.py_in
@@ -199,25 +199,31 @@ class AOControl(ContextDecorator):
                         for k, v in self.storage_options_dict.iteritems()])
 
     def __enter__(self):
+        # We first check if we can get the guc value from the database using 
the
+        # show command. If this fails, then we assume that the guc doesn't 
exist
+        # and we ignore the error and return. This can happen when platform is
+        # postgres, or platform is gpdb but the guc doesn't exist anymore.
         try:
             _storage_options_str = plpy.execute(
                 "show 
gp_default_storage_options")[0]["gp_default_storage_options"]
-            self._parse_gp_default_storage_options(_storage_options_str)
+        except plpy.SPIError:
+            self.guc_exists = False
+            return self
 
+        if self.guc_exists:
+            self._parse_gp_default_storage_options(_storage_options_str)
             # Set APPENDONLY=<enable> after backing up existing value
             self.was_ao_enabled = self.storage_options_dict['appendonly']
             self.storage_options_dict['appendonly'] = self.to_enable
-            plpy.execute("set gp_default_storage_options={0}".
+            plpy.execute("set gp_default_storage_options='{0}'".
                          format(self._gp_default_storage_options))
-        except plpy.SPIError:
-            self.guc_exists = False
-        finally:
-            return self
+
+        return self
 
     def __exit__(self, *args):
         if self.guc_exists:
             self.storage_options_dict['appendonly'] = self.was_ao_enabled
-            plpy.execute("set gp_default_storage_options={0}".
+            plpy.execute("set gp_default_storage_options='{0}'".
                          format(self._gp_default_storage_options))
         if args and args[0]:
             # an exception was raised in code. We return False so that any

http://git-wip-us.apache.org/repos/asf/madlib/blob/03e82bc5/src/ports/postgres/modules/utilities/test/unit_tests/test_control.py_in
----------------------------------------------------------------------
diff --git 
a/src/ports/postgres/modules/utilities/test/unit_tests/test_control.py_in 
b/src/ports/postgres/modules/utilities/test/unit_tests/test_control.py_in
index 55bbd06..66a429e 100644
--- a/src/ports/postgres/modules/utilities/test/unit_tests/test_control.py_in
+++ b/src/ports/postgres/modules/utilities/test/unit_tests/test_control.py_in
@@ -55,8 +55,8 @@ class ControlTestCase(unittest.TestCase):
         with self.subject.AOControl(False) as C:
             self.assertFalse(C.storage_options_dict['appendonly'])
         self.plpy_mock_execute.assert_called_with(
-            "set gp_default_storage_options=compresstype=none,blocksize=32768"
-            ",appendonly=True,orientation=row,checksum=true")
+            "set gp_default_storage_options='compresstype=none,blocksize=32768"
+            ",appendonly=True,orientation=row,checksum=true'")
 
     def test_ao_control_true(self):
         option = ('appendonly=true,blocksize=32768,compresstype=none,'
@@ -65,8 +65,8 @@ class ControlTestCase(unittest.TestCase):
         with self.subject.AOControl(True) as C:
             self.assertTrue(C.storage_options_dict['appendonly'])
         self.plpy_mock_execute.assert_called_with(
-            "set gp_default_storage_options=compresstype=none,blocksize=32768"
-            ",appendonly=True,orientation=row,checksum=true")
+            "set gp_default_storage_options='compresstype=none,blocksize=32768"
+            ",appendonly=True,orientation=row,checksum=true'")
 
     def test_ao_control_missing(self):
         option = ('appendonly=true,blocksize=32768,compresstype=none,'

Reply via email to