tencentcloud-dlc-connector.
pip install -i https://mirrors.tencent.com/pypi/simple/ tencentcloud-dlc-connector
import tdlc_connectorimport datetimefrom tdlc_connector import constantsconn = tdlc_connector.connect(region="<REGION>",secret_id="<SECRET_ID>",secret_key="<SECRET_KEY>",token=None,endpoint=None,catalog=constants.Catalog.DATALAKECATALOG,engine="<ENGINE>",engine_type=constants.EngineType.AUTO,result_style=constants.ResultStyles.LIST,download=False,mode=constants.Mode.LASY,database='',config={},callback=None,callback_events=None,)
Parameter | Description |
region | Engine Region, such as ap-nanjing, ap-beijing, ap-guangzhou, ap-shanghai, ap-chengdu, ap-chongqing, na-siliconvalley, ap-singapore, ap-hongkong |
secret_id | Tencent Cloud SecretID |
secret_key | Tencent Cloud SecretKey |
token | (Optional) Temporary Secret Token |
endpoint | (Optional) Connect to the service node |
engine | Engine name used, for example "test_python" |
engine_type | (Optional) Engine type: corresponding to the engine type of the engine name, default value constants.EngineType.AUTO For example: AUTO, PRESTO, SPARK, SPARK_BATCH |
result_style | (Optional) Format of the returned result, options are LIST/DICT |
download | |
mode | (Optional) Mode. Supports ALL/LAZY/STREAM |
database | (Optional) Default database |
config | (Optional) Submit to cluster configuration |
callback | (Optional) Callback function, function signature def cb(statement_id, status) |
callback_events | (Optional) Callback trigger event, used in conjunction with callback, see callback mechanism description for details |
driver_size | (Optional) Driver node size, default value constants.PodSize.SMALL (Only valid for SPARK_BATCH clusters) Optional values: SMALL, MEDIUM, LARGE, XLARGE, M_SMALL, M_MEDIUM, M_LARGE, M_XLARGE |
executor_size | (Optional) Executor node size, default value constants.PodSize.SMALL (Only valid for SPARK_BATCH clusters)
Optional values: SMALL, MEDIUM, LARGE, XLARGE, M_SMALL, M_MEDIUM, M_LARGE, M_XLARGE |
executor_num | (Optional) Number of Executor nodes, default value 1 (Only valid for SPARK_BATCH clusters) |
executor_max_num | (Optional) Maximum number of Executor nodes, if not equal to executor_num, then enable Dynamic Resource Allocation (Only valid for SPARK_BATCH clusters) |
Serial number | download | mode | Description |
1 | False | ALL | Fetch all data from the interface, can only fetch data after completion |
2 | False | LASY | Fetch data from the interface, delay fetching data to the server based on the amount fetched |
3 | False | STREAM | Same as LASY mode |
4 | True | ALL | Download all results from COS (requires COS read permission) using local temporary storage, recommended for large data volumes |
5 | True | LASY | Download results from COS (requires COS read permission), delay downloading files based on fetch data volume |
6 | True | STREAM | Read result stream from COS in real-time (requires COS read permission), slower performance, extremely low local memory disk usage ratio |
# Basic Operationscursor = conn.cursor()count = cursor.execute("SELECT 1")print(cursor.fetchone()) # Read one line of datafor row in cursor.fetchall(): # Read the remaining multiple lines of dataprint(row)# Use the pyformat formatcursor.execute("SELECT * FROM dummy WHERE date < %s", datetime.datetime.now())cursor.execute("SELECT * FROM dummy WHERE status in %s", (('SUCCESS', 'INIT', 'FAIL'),))cursor.execute("SELECT * FROM dummy WHERE date < %(date)s AND status = %(status)s", {'date': datetime.datetime.now(), 'status': 'SUCCESS'})# Use BULK methodcursor.executemany("INSERT INTO dummy VALUES(%s, %s)", [('Zhang San', 18), ('Li Si', 20)])
conn.cursor()
.cursor.execute("SELECT 1")
, and the result is assigned to the variable count.
cursor.fetchone()
method and printed out.import tdlc_connectorimport datetimefrom tdlc_connector import constantsdef tdlc_connector_callback(statement_id, state):'''parmas: statement_id Quest idparams: state Task status. The enumeration value is constants.TaskStatus'''print(statement_id, state)conn = tdlc_connector.connect(region="<REGION>",secret_id="<SECRET_ID>",secret_key="<SECRET_KEY>",engine="<ENGINE>",engine_type=constants.EngineType.SPARK,result_style=constants.ResultStyles.LIST,callback=tdlc_connector_callback,callback_events=[constants.CallbackEvent.ON_INIT, constants.CallbackEvent.ON_SUCCESS])cursor = conn.cursor()cursor.execute("SELECT 1")cursor.fetchone()# The callback function is called when the task is initialized and the task is successful
from tdlc_connector import constantsconn = tdlc_connector.connect(region="<REGION>",secret_id="<SECRET_ID>",secret_key="<SECRET_KEY>",engine="<ENGINE>", # Select the spark job engineresult_style=constants.ResultStyles.LIST,driver_size=constants.PodSize.SMALL, # Select Driver Specificationsexecutor_size=constants.PodSize.SMALL, # Select the Executor specificationexecutor_num=1, # Set the number of Executorsexecutor_max_num=1, # Set the maximum number of executors. If it is not equal to {executor_num}, enable dynamic resource allocation)
from tdlc_connector import constantsconn = tdlc_connector.connect(region="<REGION>",secret_id="<SECRET_ID>",secret_key="<SECRET_KEY>",engine="<ENGINE>",engine_type=constants.EngineType.AUTO # This parameter can be set to AUTO or not to drive automatic inference)
from tdlc_connector import constants, formatsformats.FORMAT_STRING_NULL = '\\1'conn = tdlc_connector.connect(region="<REGION>",secret_id="<SECRET_ID>",secret_key="<SECRET_KEY>",engine="<ENGINE>",result_style=constants.ResultStyles.LIST)
Was this page helpful?