Exemplo n.º 1
0
    def load_data(self, path, overwrite=False, partition=None):
        """Load data into an Impala table.

        Parameters
        ----------
        path
            Data to load
        overwrite
            Overwrite the existing data in the entire table or indicated
            partition
        partition
            If specified, the partition must already exist
        """
        if partition is not None:
            partition_schema = self.partition_schema()
        else:
            partition_schema = None

        stmt = ddl.LoadData(
            self._qualified_name,
            path,
            partition=partition,
            partition_schema=partition_schema,
        )

        return self._client.raw_sql(stmt.compile())
Exemplo n.º 2
0
def test_load_data_unpartitioned():
    path = '/path/to/data'
    stmt = ddl.LoadData('functional_alltypes', path, database='foo')

    result = stmt.compile()
    expected = ("LOAD DATA INPATH '/path/to/data' "
                "INTO TABLE foo.`functional_alltypes`")
    assert result == expected

    stmt.overwrite = True
    result = stmt.compile()
    expected = ("LOAD DATA INPATH '/path/to/data' "
                "OVERWRITE INTO TABLE foo.`functional_alltypes`")
    assert result == expected
Exemplo n.º 3
0
def test_load_data_partitioned():
    path = '/path/to/data'
    part = {'year': 2007, 'month': 7}
    part_schema = ibis.schema([('year', 'int32'), ('month', 'int32')])
    stmt = ddl.LoadData(
        'functional_alltypes',
        path,
        database='foo',
        partition=part,
        partition_schema=part_schema,
    )

    result = stmt.compile()
    expected = """\
LOAD DATA INPATH '/path/to/data' INTO TABLE foo.`functional_alltypes`
PARTITION (year=2007, month=7)"""
    assert result == expected

    stmt.overwrite = True
    result = stmt.compile()
    expected = """\
LOAD DATA INPATH '/path/to/data' OVERWRITE INTO TABLE foo.`functional_alltypes`
PARTITION (year=2007, month=7)"""
    assert result == expected