dropbox / dropbox/PyHive

Question: How can I get result types for a Hive query?

Open
#27 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
1.7k
Forks
545
PR merge metrics
No merged PRs in 30d

Description

`.description` gives:

```
[(u'my_schema.col_one', u'BIGINT_TYPE', None, None, None, None, True),
(u'my_schema.col_two', u'DATE_TYPE', None, None, None, None, True),
(u'my_schema.col_three',
u'BIGINT_TYPE',
None,
None,
None,
None,
True)]
```

So the second field gives the types, but I would really like to be able to get at column types I can use in DDL statements. In this case, BIGINT, DATE, and BIGINT.

**What's the best way to do this?**

I see two options:
1. String manipulation. Strip `_TYPE` off.
2. Add it to `DBAPITypeObject` by looking it up in `TCLIService.constants.TYPE_NAMES`:

```
for type_id in constants.PRIMITIVE_TYPES:
name = ttypes.TTypeId._VALUES_TO_NAMES[type_id]
setattr(sys.modules[__name__], name, DBAPITypeObject([name], constants.TYPE_NAMES[type_id]))
```

Then add `__str__` to `DBAPITypeObject` which returns a valid column name for use in DDL statements.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.