kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject kudu git commit: [python] - Expand KuduError capabilities
Date Mon, 07 Nov 2016 20:40:52 GMT
Repository: kudu
Updated Branches:
  refs/heads/master 8389f482b -> 46f52bcde


[python] - Expand KuduError capabilities

The Python client currently doesn't support the full error reporting
capabilities of the KuduError class. This patch exposes most of them
and includes tests.

Change-Id: I4947a663ae09ec2fc9580876521252670d081aa1
Reviewed-on: http://gerrit.cloudera.org:8080/4885
Reviewed-by: Jean-Daniel Cryans <jdcryans@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/46f52bcd
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/46f52bcd
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/46f52bcd

Branch: refs/heads/master
Commit: 46f52bcde47d48cecbe847f66718e3492488d569
Parents: 8389f48
Author: Jordan Birdsell <jordantbirdsell@gmail.com>
Authored: Sat Oct 29 16:30:43 2016 -0400
Committer: Jean-Daniel Cryans <jdcryans@apache.org>
Committed: Mon Nov 7 20:40:36 2016 +0000

----------------------------------------------------------------------
 python/kudu/client.pyx           | 24 +++++++++++++++++++++++-
 python/kudu/tests/test_client.py | 25 +++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/46f52bcd/python/kudu/client.pyx
----------------------------------------------------------------------
diff --git a/python/kudu/client.pyx b/python/kudu/client.pyx
index 5cfb5b7..cec61ff 100644
--- a/python/kudu/client.pyx
+++ b/python/kudu/client.pyx
@@ -2308,7 +2308,29 @@ cdef class KuduError:
             del self.error
 
     def failed_op(self):
-        raise NotImplementedError
+        """
+        Get debug string representation of the failed operation.
+
+        Returns
+        -------
+        op : str
+        """
+        return frombytes(self.error.failed_op().ToString())
+
+    def was_possibly_successful(self):
+        """
+        Check if there is a chance that the requested operation was successful.
+
+        In some cases, it is possible that the server did receive and
+        successfully perform the requested operation, but the client can't
+        tell whether or not it was successful. For example, if the call times
+        out, the server may still succeed in processing at a later time.
+
+        Returns
+        -------
+        result : bool
+        """
+        return self.error.was_possibly_successful()
 
     def __repr__(self):
         return "KuduError('%s')" % (self.error.status().ToString())

http://git-wip-us.apache.org/repos/asf/kudu/blob/46f52bcd/python/kudu/tests/test_client.py
----------------------------------------------------------------------
diff --git a/python/kudu/tests/test_client.py b/python/kudu/tests/test_client.py
index 10bbda4..4896cb2 100644
--- a/python/kudu/tests/test_client.py
+++ b/python/kudu/tests/test_client.py
@@ -206,6 +206,31 @@ class TestClient(KuduTestBase, unittest.TestCase):
         scanner = table.scanner().open()
         assert len(scanner.read_all_tuples()) == 0
 
+    def test_failed_write_op(self):
+        # Insert row
+        table = self.client.table(self.ex_table)
+        session = self.client.new_session()
+        session.apply(table.new_insert({'key': 1}))
+        session.flush()
+
+        # Attempt to insert row again
+        session.apply(table.new_insert({'key': 1}))
+        self.assertRaises(kudu.KuduBadStatus, session.flush)
+
+        # Check errors
+        errors, overflowed = session.get_pending_errors()
+        self.assertFalse(overflowed)
+        self.assertEqual(len(errors), 1)
+        error = errors[0]
+        # This test passes because we currently always return
+        # True.
+        self.assertTrue(error.was_possibly_successful())
+        self.assertEqual(error.failed_op(), 'INSERT int32 key=1')
+
+        # Delete inserted row
+        session.apply(table.new_delete({'key': 1}))
+        session.flush()
+
     def test_session_auto_open(self):
         table = self.client.table(self.ex_table)
         scanner = table.scanner()


Mime
View raw message