Skip to content

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

@RasterBurn

Description

@RasterBurn

.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions