Migrate the data in the sql service database to clickhourse

First of all, we need to create corresponding tables in clickhourse according to the tables of the sql server database:

CREATE TABLE IF NOT EXISTS default.PosSalSheet(
                 SheetID String,
                 PosType Int8,
                 Status Int8,
                 IsRefund Int8,
RefundStatus Int8,
SheetDate DateTime64,
AppName String,
ShopID String,
ShopName String,
DtbCYTypeID Int8,
BaseID String,
BaseName String,
SalesAmo Decimal128(4),
Amo Decimal128(4),
Discount Decimal32(4),
DisAmo Decimal128(4),
CouponAmo Decimal128(4),
ExchangeAmo Decimal128(4),
AdjAmo Decimal128(4),
FeeAmo Decimal128(4),
FreightAmo Decimal128(4),
PackagingAmo Decimal128(4),
PolybagAmo Decimal128(4),
TotalAmo Decimal128(4),
PayAmo  Decimal128(4),
ChangeAmo Decimal128(4),
CostAmo Decimal128(4),
CreatedDate DateTime64
             )
             ENGINE = MergeTree
             ORDER BY (SheetID )
             SETTINGS index_granularity = 8192;

Then here I use the data migration performed by datax:

Open the decompressed datax directory on the server, put the written json statement in the job folder, and enter the statement

python bin/datax.py  ./job/possalsheet.json

perform tasks

The content of possalsheet.json is as follows:

{
    "job": {
        "content": [
            {
                "reader": {
                    "name": "sqlserverreader",
                    "parameter": {
                        "connection": [
                            {
                                "jdbcUrl": [
                                    "jdbc:sqlserver://47.106.64.222:1433;DatabaseName=HBBPosData"
                                ],
                                "querySql": [
                                    " select SheetID,PosType,Status,IsRefund,RefundStatus,SheetDate,AppName,ShopID,ShopName,DtbCYTypeID,BaseID,BaseName,SalesAmo,Amo,Discount,DisAmo,CouponAmo,ExchangeAmo,AdjAmo,FeeAmo,FreightAmo,PackagingAmo,PolybagAmo,TotalAmo,PayAmo,ChangeAmo,CostAmo,CreatedDate from PosSalSheet"
                                ]
                            }
                        ],
                        "username": "Hnust",
                        "password": "Hnust@202302061746YXJ.."
                    }
                },
                "writer": {
                    "name": "clickhousewriter",
                    "parameter": {
                        "username": "default",
                        "password": "123456",
                        "column": [ "*" ],
                        "connection": [
                            {
                                "jdbcUrl": "jdbc:clickhouse://192.168.186.154:8123/default",
                                "table": [
                                    "PosSalSheet"
                                ]
                            }
                        ],
                        "preSql": [],
                        "postSql": [],
                        "batchSize": 65536,
                        "batchByteSize": 134217728,
                        "dryRun": false,
                        "writeMode": "insert"
                    }
                }
              
            }
        ],
        "setting": {
            "speed": {
                "channel": "1"
            }
        }
    }
}

Finally completed the replacement, if you want the compressed file of datax, I put it here in my resources

Guess you like

Origin blog.csdn.net/CSH__/article/details/129310466