示例#1
0
def test_query_avro(con, test_data_dir, tmp_db):
    hdfs_path = pjoin(test_data_dir, 'avro/tpch_region_avro')

    avro_schema = {
        "fields": [
            {"type": ["int", "null"], "name": "R_REGIONKEY"},
            {"type": ["string", "null"], "name": "R_NAME"},
            {"type": ["string", "null"], "name": "R_COMMENT"},
        ],
        "type": "record",
        "name": "a",
    }

    table = con.avro_file(hdfs_path, avro_schema, database=tmp_db)

    qualified_name = table.op().name
    _, name, _ = fully_qualified_re.match(qualified_name).groups()

    # table exists
    assert name in con.list_tables(database=tmp_db)

    expr = table.r_name.value_counts()
    expr.execute()

    assert table.count().execute() == 5

    df = table.execute()
    assert len(df) == 5
示例#2
0
文件: client.py 项目: cpcloud/ibis
 def _match_name(self):
     m = fully_qualified_re.match(self._qualified_name)
     if not m:
         raise com.IbisError(
             'Cannot determine database name from {}'.format(
                 self._qualified_name))
     db, quoted, unquoted = m.groups()
     return db, quoted or unquoted
示例#3
0
    def list_tables(self, like=None, database=None):
        statement = 'SHOW TABLES'
        if database is not None:
            statement += f' IN {database}'
        if like:
            m = fully_qualified_re.match(like)
            if m:
                database, quoted, unquoted = m.groups()
                like = quoted or unquoted
                return self.list_tables(like=like, database=database)
            statement += f" LIKE '{like}'"

        return self._filter_with_like(
            [row[0] for row in self.raw_sql(statement).fetchall()])
示例#4
0
    def rename(self, new_name, database=None):
        """Rename table inside Impala.

        References to the old table are no longer valid.
        """
        m = fully_qualified_re.match(new_name)
        if not m and database is None:
            database = self._database
        statement = RenameTable(
            self._qualified_name, new_name, new_database=database
        )
        self._client.raw_sql(statement)

        op = self.op().change_name(statement.new_qualified_name)
        return type(self)(op)
示例#5
0
 def _match_name(self):
     m = fully_qualified_re.match(self._qualified_name)
     if not m:
         return None, self._qualified_name
     db, quoted, unquoted = m.groups()
     return db, quoted or unquoted