文章目录
- 一、python的数据表处理
- 二、05.05 周日
- 2.1)python的一些语法
- 2.2)Dubbo
- 2.3) Golang
一、python的数据表处理
1)代码作用
下边的代码主要是涉及 python链接数据库,并从数据库中获取到 元祖的返回结果,继续对返回的结果进行 元祖,列表的转换即分组处理,最终得到批量id删除的sql语句,删除需要删除的数据。
2)详细代码
"""
删除 Doris库中某些表中无效的数据
"""
import mysql.connector
import socket
import socks
import pandas as pd
import pymysql
from sqlalchemy import create_engine, text
import csv
from datetime import datetime
# Tidb数据库
def DorisTableInfo(databaseName, env):
if env == "online":
# Doris
db = pymysql.connect(host="yourHost",port=6666,user="yourUser",password="yourPwd",database=databaseName)
cursor = db.cursor()
cursor.execute("set names utf8")
cursor.execute("SET character_set_connection=utf8;")
dbName = "MY_DB.tableName"
sql="select id from %s where status = 'InValid' order by id asc limit 500000;" % (dbName)
print("查询要删除的数据语句:", sql)
cursor.execute(sql)
data = cursor.fetchall()
print("查询 %s 需要物理删除的数据量: " % (dbName), len(data))
list = []
for i in range(0, len(data)):
list.append(data[i][0])
# print(list)
# 1000个一拆分
listItem=group_list(list, 1000)
for i in range(len(listItem)):
deleteIds = ','.join(str(item) for item in listItem[i])
deleteSql = "delete from %s where id in (%s)" % (dbName, deleteIds)
print("[%s/%s]" % (i, len(listItem)), deleteSql)
cursor.execute(deleteSql)
def group_list(lst, group_size):
groups = {}
for i, item in enumerate(lst):
group_number = i // group_size
if group_number not in groups:
groups[group_number] = []
groups[group_number].append(item)
return [group for _, group in sorted(groups.items())]
# Doris 数据库
databaseName = "MY_DB"
env = "online"
print("start-------")
DorisTableInfo(databaseName, env)
print("done-------")
二、05.05 周日
2.1)python的一些语法
- python的推导式
>>> myGirl=['LiuYifei', 'XiaoCangYouzi', 'JiZeMingbu']
>>> newGril=[name for name in myGirl if name.startswith('J')]
>>> newGril
['JiZeMingbu']
2.2)Dubbo
- https://cn.dubbo.apache.org/zh-cn/overview/core-features/service-definition/
2.3) Golang
- 运行golang
在 Linux 的 shell 界面中运行 Go(Golang)程序非常简单。下面是一种基本的方法:
编写 Go 程序: 首先,你需要编写一个 Go 程序。比如,你可以创建一个名为 hello.go 的文件,并在其中编写以下简单的 Go 代码:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
使用 go build 命令编译: 在终端中,使用 go build 命令来编译你的 Go 程序。进入到包含 hello.go 文件的目录,然后运行以下命令:
go build hello.go
这将会在当前目录下生成一个名为 hello 的可执行文件。
运行可执行文件: 接着,在终端中直接运行生成的可执行文件 hello:
./hello
这会在终端中输出 Hello, Go!。
请确保你已经在 Linux 中安装了 Go 编程语言,并且设置了正确的环境变量。可以通过运行 go version
命令来检查你的 Go 版本。如果没有安装 Go,你需要先安装它并配置好环境变量,然后才能按照上述步骤进行。