def save(projectCode,featureId, featureValue, featureTime,updateCycle,scriptName,placeholderDim1,placeholderDim2,placeholderDim3,placeholderDim4):
hostname = '172.16.24.75'
hbaseTableName = 'feature_repo_debug'
updateCycleStr='hourly,daily,weekly,monthly,quarterly,yearly'
updateCycleList = []
updateCycleArray = updateCycleStr.split(",")
for item in updateCycleArray:
updateCycleList.append(item)
conn = happybase.Connection(host=hostname,port=9090,protocol='compact',transport='framed')
table = conn.table(hbaseTableName)
#字段非空判断
if projectCode is None:
raise Exception('参数1,项目编码 字段不能为空!')
if featureId is None:
raise Exception('参数2,指标id 字段不能为空!')
if featureValue is None:
featureValue = None
if featureTime is None:
raise Exception('参数4,指标时间维度值 字段不能为空!')
if updateCycle is None:
raise Exception('参数5,更新周期 字段不能为空!')
elif updateCycle not in updateCycleList:
raise Exception('参数5,更新周期 的值必须在'+ updateCycle + '中!')
if scriptName is None:
raise Exception('参数6,脚本名称 不能为空!')
timestamps = time.localtime()
createdAt = time.strftime("%Y-%m-%d %H:%M:%S", timestamps)
row_key = str(uuid.uuid4())
# conn = happybase.Connection(hostname)
# table = conn.table(hbaseTableName)
# conn.close()
return table.put(row_key, {'cf1:project_code':projectCode, 'cf1:feature_id':featureId,'cf1:feature_value':featureValue,'cf1:feature_time':featureTime,'cf1:update_cycle':updateCycle,'cf1:script_name': scriptName,'cf1:placeholder_dim_1': placeholderDim1, 'cf1:placeholder_dim_2': placeholderDim2,'cf1:placeholder_dim_3':placeholderDim3,'cf1:placeholder_dim_4':placeholderDim4,'cf1:created_at':createdAt})
def batchsave(list1):
hostname = '172.16.24.75'
hbaseTableName = 'feature_repo_debug'
updateCycleStr='hourly,daily,weekly,monthly,quarterly,yearly'
updateCycleList = []
updateCycleArray = updateCycleStr.split(",")
for item in updateCycleArray:
updateCycleList.append(item)
conn = happybase.Connection(host=hostname,port=9090,protocol='compact',transport='framed')
table = conn.table(hbaseTableName)
with table.batch() as bat:
for item in list1:
# array = item.split(',')
projectCode = item[0]
featureId = item[1]
featureValue = item[2]
featureTime = item[3]
updateCycle = item[4]
scriptName = item[5]
placeholderDim1 = ''
placeholderDim2 = ''
placeholderDim3 = ''
placeholderDim4 = ''
hostname = '172.16.24.75'
hbaseTableName = 'feature_repo_debug'
updateCycleStr='hourly,daily,weekly,monthly,quarterly,yearly'
updateCycleList = []
updateCycleArray = updateCycleStr.split(",")
for item in updateCycleArray:
updateCycleList.append(item)
conn = happybase.Connection(host=hostname,port=9090,protocol='compact',transport='framed')
table = conn.table(hbaseTableName)
#字段非空判断
if projectCode is None:
raise Exception('参数1,项目编码 字段不能为空!')
if featureId is None:
raise Exception('参数2,指标id 字段不能为空!')
if featureValue is None:
featureValue = None
if featureTime is None:
raise Exception('参数4,指标时间维度值 字段不能为空!')
if updateCycle is None:
raise Exception('参数5,更新周期 字段不能为空!')
elif updateCycle not in updateCycleList:
raise Exception('参数5,更新周期 的值必须在'+ updateCycle + '中!')
if scriptName is None:
raise Exception('参数6,脚本名称 不能为空!')
timestamps = time.localtime()
createdAt = time.strftime("%Y-%m-%d %H:%M:%S", timestamps)
row_key = str(uuid.uuid4())
# conn = happybase.Connection(hostname)
# table = conn.table(hbaseTableName)
# conn.close()
table.put(row_key, {'cf1:project_code':projectCode, 'cf1:feature_id':featureId,'cf1:feature_value':featureValue,'cf1:feature_time':featureTime,'cf1:update_cycle':updateCycle,'cf1:script_name': scriptName,'cf1:placeholder_dim_1': placeholderDim1, 'cf1:placeholder_dim_2': placeholderDim2,'cf1:placeholder_dim_3':placeholderDim3,'cf1:placeholder_dim_4':placeholderDim4,'cf1:created_at':createdAt})