|
11 | 11 | # See the License for the specific language governing permissions and |
12 | 12 | # limitations under the License. |
13 | 13 |
|
14 | | -from odps import ODPS, tunnel |
15 | 14 | from runtime.db_writer.base import BufferedDBWriter |
16 | 15 |
|
17 | 16 |
|
18 | 17 | class MaxComputeDBWriter(BufferedDBWriter): |
| 18 | + """ |
| 19 | + MaxComputeDBWriter is used to write the Python row data into |
| 20 | + the MaxCompute table. |
| 21 | +
|
| 22 | + Args: |
| 23 | + conn: the database connection object. |
| 24 | + table_name (str): the MaxCompute table name. |
| 25 | + table_schema (list[str]): the column names of the MaxCompute table. |
| 26 | + buff_size (int): the buffer size to be flushed. |
| 27 | + """ |
19 | 28 | def __init__(self, conn, table_name, table_schema, buff_size): |
20 | | - return super(MaxComputeDBWriter, |
21 | | - self).__init__(conn, table_name, table_schema, buff_size) |
| 29 | + super(MaxComputeDBWriter, self).__init__(conn, table_name, |
| 30 | + table_schema, buff_size) |
| 31 | + |
| 32 | + # NOTE: import odps here instead of in the front of this file, |
| 33 | + # so that we do not need the odps package installed in the Docker |
| 34 | + # image if we do not use MaxComputeDBWriter. |
| 35 | + from odps import tunnel |
| 36 | + self.compress = tunnel.CompressOption.CompressAlgorithm.ODPS_ZLIB |
22 | 37 |
|
23 | 38 | def flush(self): |
24 | | - compress = tunnel.CompressOption.CompressAlgorithm.ODPS_ZLIB |
| 39 | + """ |
| 40 | + Flush the row data into the MaxCompute table. |
| 41 | +
|
| 42 | + Returns: |
| 43 | + None |
| 44 | + """ |
25 | 45 | self.conn.write_table(self.table_name, |
26 | 46 | self.rows, |
27 | | - compress_option=compress) |
| 47 | + compress_option=self.compress) |
28 | 48 | self.rows = [] |
0 commit comments