继国庆节 SmartCode 正式版(SmartCode.Generator)发布之后,SmartCode 迎来了新的能力 SmartCode.ETL !
SmartCode 正式版从开始发布就从未说过自己仅仅是个代码生成器,这点上从我第一次宣布SmartCode正式开源的文章就可以说明:《SmartCode 不只是代码生成器》,这不仅仅是一句推广语!
SmartCode.Generator相信不少同学都用过各种代码生成器,这里我就不做详细介绍了,如果想体验 SmartCode.Generator 请至 https://www.cnblogs.com/Ahoo-Wang/p/SmartCode-intro.html 配置好数据库连接,一键生成解决方案。
Why SmartCode.ETL相信不少已经落地微服务架构方案的同学都会遇到同样的问题:
业务方的查询需求似乎总是跨微服务DB的
领导层需要查看的报表数据总是全局的(需要聚合跨微服务DB的)
So SmartCode.ETL从多个微服务DB 同步业务聚合查询数据到 all_biz DB (解决:微服务架构一定会遇到的业务方需要跨微服务DB查询的问题)
从 all_biz DB 同步聚合分析数据到 report DB (解决:领导层查看的报表数据聚合问题)
How SmartCode.ETL
安装 SmartCode from dotnet-cli
dotnet tool install --global SmartCode.CLI使用 SmartCode.Generator 生成 同步Sql表结构脚本,以及 SmartCode.ETL 构建配置
执行Sql同步脚本初始化表结构
使用任务调度(crontab) + SmartCode.ETL 同步分析数据
通过持久化 etl_task 监控 etl执行情况(目前支持PostgreSql)
简单来说就是SmartCode生成SmartCode,任务调度执行SmartCode命令行。(这真的不是先有鸡还是蛋的问题.....)
SmartCode 插件概览 { "SmartCode": { "Version": "v1.16.15", "Plugins": [ { "Type": "SmartCode.IDataSource,SmartCode", "ImplType": "SmartCode.NoneDataSource,SmartCode" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.App.BuildTasks.ClearBuildTask,SmartCode.App" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.App.BuildTasks.ProjectBuildTask,SmartCode.App" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.App.BuildTasks.MultiTemplateBuildTask,SmartCode.App" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.App.BuildTasks.ProcessBuildTask,SmartCode.App" }, { "Type": "SmartCode.IOutput,SmartCode", "ImplType": "SmartCode.App.Outputs.FileOutput,SmartCode.App" }, { "Type": "SmartCode.IDataSource,SmartCode", "ImplType": "SmartCode.Generator.DbTableSource,SmartCode.Generator" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.Generator.BuildTasks.TableBuildTask,SmartCode.Generator" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.Generator.BuildTasks.SingleBuildTask,SmartCode.Generator" }, { "Type": "SmartCode.INamingConverter,SmartCode", "ImplType": "SmartCode.Generator.TableNamingConverter,SmartCode.Generator" }, { "Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine", "ImplType": "SmartCode.TemplateEngine.Impl.HandlebarsTemplateEngine,SmartCode.TemplateEngine" }, { "Type": "SmartCode.TemplateEngine.ITemplateEngine,SmartCode.TemplateEngine", "ImplType": "SmartCode.TemplateEngine.Impl.OfficialRazorTemplateEngine,SmartCode.TemplateEngine" }, { "Type": "SmartCode.Generator.IDbTypeConverter,SmartCode.Generator", "ImplType": "SmartCode.Generator.DbTypeConverter.DefaultDbTypeConverter,SmartCode.Generator" }, { "Type": "SmartCode.IDataSource,SmartCode", "ImplType": "SmartCode.ETL.ExtractDataSource,SmartCode.ETL" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.ETL.BuildTasks.TransformBuildTask,SmartCode.ETL" }, { "Type": "SmartCode.ETL.ITransformEngine,SmartCode.ETL", "ImplType": "SmartCode.ETL.TransformEngine.RazorTransformEngine,SmartCode.ETL" }, { "Type": "SmartCode.IBuildTask,SmartCode", "ImplType": "SmartCode.ETL.BuildTasks.LoadBuildTask,SmartCode.ETL" }, { "Type": "SmartCode.ETL.IETLRepository,SmartCode.ETL", "ImplType": "SmartCode.ETL.NoneETLRepository,SmartCode.ETL" }, { "Type": "SmartCode.ETL.IETLRepository,SmartCode.ETL", "ImplType": "SmartCode.ETL.PostgreSql.PGETLRepository,SmartCode.ETL.PostgreSql", "Paramters": { "ConnectionString": "Server=localhost;Port=5432;User Id=postgres;Password=SmartSql; Database=smartcode_etl;" } } ] } } ETL 构建配置 Author: Ahoo Wang DataSource: Name: Extract Paramters: DbProvider: SqlServer ConnectionString: Data Source=.;Initial Catalog=SmartSqlDB;Integrated Security=True Query: SELECT [Id],[UserName],[Status],[LastLoginTime],[CreationTime],[ModifyTime],[Deleted] FROM [T_User] With(NoLock) Where ModifyTime>@LastMaxModifyTime PKColumn: Id AutoIncrement: true ModifyTime: ModifyTime Paramters: ETLCode: SmartCode.ETL.Test ETLRepository: PG Build: Transform: Type: Transform Paramters: Script: Load2PostgreSql: Type: Load Paramters: DbProvider: PostgreSql ConnectionString: Server=localhost;Port=5432;User Id=postgres;Password=SmartSql; Database=smartsql_db; Table: t_user__temp PreCommand: CREATE TABLE t_user__temp( LIKE t_user ); PostCommand: "Delete From t_user as source Where EXISTS(select * from t_user__temp temp where temp.id=source.id); Insert Into t_user SELECT * From t_user__temp; Drop Table t_user__temp; " ColumnMapping: [{Column: Id,Mapping: id} ,{Column: UserName,Mapping: user_name} ,{Column: Status,Mapping: status} ,{Column: LastLoginTime,Mapping: last_login_time} ,{Column: CreationTime,Mapping: creation_time} ,{Column: ModifyTime,Mapping: modify_time} ,{Column: Deleted,Mapping: deleted}] 根 Paramters 参数名 说明ETLCode ETL任务Code,区分任务类型,唯一
ETLRepository ETL任务持久化仓储,None/PG
DataSource 参数说明