[ 
https://issues.apache.org/jira/browse/PHOENIX-6917?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17708222#comment-17708222
 ] 

ASF GitHub Bot commented on PHOENIX-6917:
-----------------------------------------

stoty commented on code in PR #124:
URL: 
https://github.com/apache/phoenix-queryserver/pull/124#discussion_r1156738877


##########
python-phoenixdb/phoenixdb/cursor.py:
##########
@@ -27,7 +27,7 @@
 # TODO see note in Cursor.rowcount()
 MAX_INT = 2 ** 64 - 1
 
-ColumnDescription = collections.namedtuple('ColumnDescription', 'name 
type_code display_size internal_size precision scale null_ok')
+ColumnDescription = collections.namedtuple('ColumnDescription', 'label 
type_code display_size internal_size precision scale null_ok')

Review Comment:
   Nit: While the names are not part of the PEP249 API, we use the names 
defined in the standard as keys.
   Please change this back to name.
   (PEP249 has no concept of name vs label, the fact that JDBC driver calls the 
visible name "label" does not need to be visible here.)



##########
python-phoenixdb/phoenixdb/tests/dbapi20.py:
##########
@@ -832,3 +832,18 @@ def test_ROWID(self):
         self.assertTrue(hasattr(self.driver,'ROWID'),
             'module.ROWID must be defined.'
             )
+
+    # https://issues.apache.org/jira/browse/PHOENIX-6917
+    def test_alias(self):
+        con = self._connect()
+        try:
+            cur = con.cursor()
+            self.executeDDL2(cur)
+            cur.execute("CREATE TABLE IF NOT EXISTS STOCK_SYMBOL (SYMBOL 
VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR)")
+            cur.execute("UPSERT INTO STOCK_SYMBOL VALUES ('CRM','SALESFORCE')")
+            cur.execute("UPSERT INTO STOCK_SYMBOL VALUES ('AAPL','APPLE Inc')")
+            cur.execute("SELECT symbol as symb, company as comp FROM 
STOCK_SYMBOL")
+            self.assertEqual(cur.description[0][0], 'SYMB')

Review Comment:
   Confirm that you can get the results via cur["SYMB"] and cur["COMP"]



##########
python-phoenixdb/phoenixdb/tests/dbapi20.py:
##########
@@ -832,3 +832,18 @@ def test_ROWID(self):
         self.assertTrue(hasattr(self.driver,'ROWID'),
             'module.ROWID must be defined.'
             )
+
+    # https://issues.apache.org/jira/browse/PHOENIX-6917

Review Comment:
   This file was adopted from an external test suite, and by convention tests 
here use the global 'barfly' and 'booze' tables.
   
   Please either keep that convention, or move this test to test_db.py, and use 
the DatabaseTestCase plumbing for opening connections and cleaning up tables.
   
   Doing either ensures that there are no tables left dangling after the test 
suite has run.



##########
python-phoenixdb/phoenixdb/tests/dbapi20.py:
##########
@@ -832,3 +832,18 @@ def test_ROWID(self):
         self.assertTrue(hasattr(self.driver,'ROWID'),
             'module.ROWID must be defined.'
             )
+
+    # https://issues.apache.org/jira/browse/PHOENIX-6917
+    def test_alias(self):
+        con = self._connect()
+        try:
+            cur = con.cursor()
+            self.executeDDL2(cur)
+            cur.execute("CREATE TABLE IF NOT EXISTS STOCK_SYMBOL (SYMBOL 
VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR)")
+            cur.execute("UPSERT INTO STOCK_SYMBOL VALUES ('CRM','SALESFORCE')")
+            cur.execute("UPSERT INTO STOCK_SYMBOL VALUES ('AAPL','APPLE Inc')")
+            cur.execute("SELECT symbol as symb, company as comp FROM 
STOCK_SYMBOL")
+            self.assertEqual(cur.description[0][0], 'SYMB')

Review Comment:
   You will probably need to change filed DictCursor uses to make that work.



##########
python-phoenixdb/phoenixdb/tests/dbapi20.py:
##########
@@ -832,3 +832,18 @@ def test_ROWID(self):
         self.assertTrue(hasattr(self.driver,'ROWID'),
             'module.ROWID must be defined.'
             )
+
+    # https://issues.apache.org/jira/browse/PHOENIX-6917
+    def test_alias(self):
+        con = self._connect()
+        try:
+            cur = con.cursor()

Review Comment:
   use cursor_factory=phoenixdb.cursor.DictCursor





> Column alias not working properly
> ---------------------------------
>
>                 Key: PHOENIX-6917
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6917
>             Project: Phoenix
>          Issue Type: Bug
>          Components: python, queryserver
>    Affects Versions: python-phoenixdb-1.2.1
>            Reporter: Satya Kommula
>            Priority: Major
>             Fix For: python-phoenixdb-1.2.2
>
>
> Get the columnLabel (the “as name”) rather than the columnName with a cursor.
> {code:java}
> calcite 💎:sql> select c1 as hello, c2 as world from int_tbl;
> +-------------+-------------+
> | c1          | c2          |
> |-------------+-------------|
> | 5           | 0           |
> | -123        | 123         |
> | 1           | 123456      |
> | -123456     | -123456     |
> | 10          | 50          |
> | -2147483648 | 1           |
> | 2147483647  | -2147483648 |
> | <null>      | 10          |
> | <null>      | <null>      |
> | 1           | 1           |
> +-------------+-------------+{code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to