Пример #1
0
def main(sql, database, table, target, deployment_id):
  # SetUp
  from pytd import Client
  from pytd import pandas_td as td
  from pytd.dbapi import connect
  import pandas as pd

  tdcli = Client(database=database)
  tdcon = connect(tdcli)

  record = td_query(sql, tdcon)
  try:
    # Predict
    predictions = make_datarobot_deployment_predictions(
      json.dumps(record),
      deployment_id)
  except DataRobotPredictionError as exc:
    print(exc)

  for pred in predictions['data']:
    record[pred['rowId']][target] = pred['prediction']

  # Upload
  df = pd.DataFrame(record)
  tdcli.load_table_from_dataframe(df, '{}.{}'.format(database, table), writer='insert_into', if_exists='overwrite')
  tdcon.close()
  print('{} records processed'.format(len(df.index)))
Пример #2
0
def call_api(sql, url, replaced_param):

  print("Reading sqlfile: {}".format(sql))
  f = open(sql, 'r')
  sqlcontent = f.read()
  f.close

  print("SQL content is:")
  print(sqlcontent)

  client = pytd.Client(
    apikey=os.environ.get('td_apikey'),
    endpoint=os.environ.get('td_endpoint'),
    database=os.environ.get('td_database'),
    default_engine=os.environ.get('td_engine')
    )
  conn = connect(client)

  print("API call start:")
  for index, row in fetch_row(sqlcontent, conn):
    u = url.replace(replaced_param, row)
    print(index, u)
    r = requests.get(u)
    print(r)

  print("API call finished")
Пример #3
0
def test_constructors():
    assert isinstance(dbapi.connect(), dbapi.Connection)