示例#1
0
def cal_avg(**kwargs):
    # pushes an XCom without a specific target
    hook = MySqlHook(mysql_conn_id='mysql_default', schema='test')

    age = hook.get_first('select round(avg(age),0) from user')

    kwargs['ti'].xcom_push(key='age', value=age)
示例#2
0
 def execute(self, context):
     hook = MySqlHook(mysql_conn_id=self.mysql_conn_id,
                      schema=self.database)
     sql = "select first_name from authors"
     result = hook.get_first(sql)
     message = "Hello {}".format(result['first_name'])
     print(message)
     return message
示例#3
0
 def test_mysql_hook_test_bulk_dump(self):
     from airflow.hooks.mysql_hook import MySqlHook
     hook = MySqlHook('airflow_ci')
     priv = hook.get_first("SELECT @@global.secure_file_priv")
     if priv and priv[0]:
         # Confirm that no error occurs
         hook.bulk_dump("INFORMATION_SCHEMA.TABLES", os.path.join(priv[0], "TABLES"))
     else:
         self.skipTest("Skip test_mysql_hook_test_bulk_load "
                       "since file output is not permitted")
示例#4
0
def doTestMysqlHook(*args, **kwargs):
    sql_hook = MySqlHook().get_hook(conn_id="mysql_operator_test_connid")
    sql = "select * from manzeng_predict_src_table;"
    result = sql_hook.get_records(sql)
    for row in result:
        print(row)
    sql = "select max(id) as max_id from manzeng_predict_src_table"
    result = sql_hook.get_records(sql)
    print('maxid:' + str(result[0][0]))
    result = sql_hook.get_first(sql)
    print('maxid:' + str(result[0]))
    LoggingMixin.log.exception("exception raise test")
    sql_hook.run(
        """insert into manzeng_result_v3(consignor_phone,prediction) values('122','33')"""
    )
示例#5
0
	def execute(self, context):
	    self.log.info('Executing: %s', self.sql)
	    hook = MySqlHook(mysql_conn_id=self.mysql_conn_id, schema=self.database)
	    result = hook.get_first(self.sql)
	    self.params['r'] = result
	    return result
 def execute(self, context):
     self.log.info('Executing: %s', self.sql)
     hook = MySqlHook(mysql_conn_id=self.mysql_conn_id,
                      schema=self.database)
     return hook.get_first(self.sql, parameters=self.parameters)