pickup_datetime timestamp, dropoff_datetime timestamp, passenger_count int, pickup_longitude double, pickup_latitude double, dropoff_longitude double, dropoff_latitude double, store_and_fwd_flag string, trip_duration int, index(key=vendor_id, ts=pickup_datetime), index(key=passenger_count, ts=pickup_datetime) ); """ # 请申请或者搭建一个集群 options = driver.DriverOptions("xxx", "xxx") driver = driver.Driver(options) if not driver.init(): print("init failed") sys.exit(-1) ok, error = driver.createDB('db_test') if not ok: print("fail to create db test") sys.exit(-1) ok, error = driver.executeDDL('db_test', ddl) if not ok: print("fail to create table ") sys.exit(-1)
def test_smoke(): print("hello") options = driver.DriverOptions(case_conf.FEDB_ZK_CLUSTER, case_conf.FEDB_ZK_PATH) sdk = driver.Driver(options) assert sdk.init() db_name = "pydb" + str(time.time_ns() % 100000) table_name = "pytable" + str(time.time_ns() % 100000) ok, error = sdk.createDB(db_name) assert ok == True ok, error = sdk.createDB(db_name) assert ok == False # create table ddl = "create table " + table_name + "(col1 string, col2 int, col3 float, col4 bigint, index(key=col1, ts=col4));" ok, error = sdk.executeDDL(db_name, ddl) assert ok == True ok, error = sdk.executeDDL(db_name, ddl) assert ok == False # insert table normal insert_normal = "insert into " + table_name + " values('hello', 123, 3.14, 1000);" ok, error = sdk.executeInsert(db_name, insert_normal) assert ok == True # insert table placeholder insert_placeholder = "insert into " + table_name + " values(?, ?, ?, ?);" ok, row_builder = sdk.getInsertBuilder(db_name, insert_placeholder) row_builder.Init(5) row_builder.AppendString("world") row_builder.AppendInt32(123) row_builder.AppendFloat(2.33) row_builder.AppendInt64(1001) ok, error = sdk.executeInsert(db_name, insert_placeholder, row_builder) assert ok == True # insert table placeholder batch ok, rows_builder = sdk.getInsertBatchBuilder(db_name, insert_placeholder) row_builder1 = rows_builder.NewRow() row_builder1.Init(2) row_builder1.AppendString("hi") row_builder1.AppendInt32(456) row_builder1.AppendFloat(2.8) row_builder1.AppendInt64(1002) row_builder2 = rows_builder.NewRow() row_builder2.Init(4) row_builder2.AppendString("word") row_builder2.AppendInt32(789) row_builder2.AppendFloat(6.6) row_builder2.AppendInt64(1003) ok, error = sdk.executeInsert(db_name, insert_placeholder, rows_builder) assert ok == True # select select = "select * from " + table_name + ";" ok, rs = sdk.executeQuery(db_name, select) assert ok == True assert rs.Size() == 4 # drop not empty db ok, error = sdk.dropDB(db_name) assert ok == False # drop table ok, error = sdk.executeDDL(db_name, "drop table " + table_name + ";") assert ok == True # drop db ok, error = sdk.dropDB(db_name) assert ok == True
# vim:fenc=utf-8 # """ """ import numpy as np import tornado.web import tornado.ioloop from fedb import driver from fedb import sql_router_sdk import json import lightgbm as lgb bst = lgb.Booster(model_file='model.txt') options = driver.DriverOptions("127.0.0.1:2181", "/fedb") fedb_driver = driver.Driver(options) if not fedb_driver.init(): sys.exit(-1) sql = """select trip_duration, passenger_count, sum(pickup_latitude) over w as vendor_sum_pl, max(pickup_latitude) over w as vendor_max_pl, min(pickup_latitude) over w as vendor_min_pl, avg(pickup_latitude) over w as vendor_avg_pl, sum(pickup_latitude) over w2 as pc_sum_pl, max(pickup_latitude) over w2 as pc_max_pl, min(pickup_latitude) over w2 as pc_min_pl, avg(pickup_latitude) over w2 as pc_avg_pl , count(vendor_id) over w2 as pc_cnt, count(vendor_id) over w as vendor_cnt from t1