cratedb写入数据
环境:
Python:3.6.5
Cratedb:4.5.1
写入程序
#!/usr/bin/env python
#coding=utf-8
from crate import client
import os, time, datetime
##client = Client(host='192.168.56.10',database='db_test',user='dbaadmin' ,password='123456')
##client = Client(host='192.168.56.10',database='db_test')
connection = client.connect("http://192.168.56.10:4200/", username="devtest", password="123456")
cursor = connection.cursor()
def insert_data_cratedb():
for i in range(1, 10):
str_i = str(i)
now_time=time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
##insert_sql = "insert into user_local(id,name) values ('%s','%s')" % (i, "name" + str_i)
insert_sql = "insert into db_test.metric_local(app,block_qps,count,exception_qps,id,machine_ip,pass_qps,resource,resource_code,rt,success_qps,timestamp,gmt_modified,gmt_create) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % (
"app" + str_i, i, i, i, i, "machine_ip" + str_i, i, "resource" + str_i, i, i, i,now_time,now_time,now_time)
ans = cursor.execute(insert_sql)
if __name__ == '__main__':
print("开始时间:"+time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
l_flag = insert_data_cratedb()
print("结束时间:"+time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
表结构:
CREATE TABLE IF NOT EXISTS "db_test"."metric_local" (
"app" TEXT NOT NULL,
"block_qps" BIGINT NOT NULL,
"count" INTEGER NOT NULL,
"exception_qps" BIGINT NOT NULL,
"gmt_create" TIMESTAMP WITH TIME ZONE NOT NULL,
"gmt_modified" TIMESTAMP WITH TIME ZONE NOT NULL,
"id" BIGINT,
"machine_ip" TEXT,
"pass_qps" BIGINT NOT NULL,
"resource" TEXT NOT NULL,
"resource_code" INTEGER NOT NULL,
"rt" DOUBLE PRECISION NOT NULL,
"success_qps" BIGINT NOT NULL,
"timestamp" TIMESTAMP WITH TIME ZONE NOT NULL,
"month" TIMESTAMP WITH TIME ZONE GENERATED ALWAYS AS date_trunc('month', "timestamp")
)
CLUSTERED INTO 4 SHARDS
PARTITIONED BY ("month")
WITH (
"allocation.max_retries" = 5,
"blocks.metadata" = false,
"blocks.read" = false,
"blocks.read_only" = false,
"blocks.read_only_allow_delete" = false,
"blocks.write" = false,
codec = 'default',
column_policy = 'strict',
"mapping.total_fields.limit" = 1000,
max_ngram_diff = 1,
max_shingle_diff = 3,
number_of_replicas = '0-1',
refresh_interval = 1000,
"routing.allocation.enable" = 'all',
"routing.allocation.total_shards_per_node" = -1,
"store.type" = 'fs',
"translog.durability" = 'REQUEST',
"translog.flush_threshold_size" = 536870912,
"translog.sync_interval" = 5000,
"unassigned.node_left.delayed_timeout" = 60000,
"write.wait_for_active_shards" = '1'
)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2019-06-21 cratedb导入json文件