A library for querying MySQL Binlog with Apache Spark structure streaming, for Spark SQL , DataFrames and MLSQL.
This library requires Spark 2.4+ (tested).
You can link against this library in your program at the following coordinates:
groupId: tech.mlsql
artifactId: spark-binlog_2.11
version: 0.1.0
- MySQL BinlogFormat should be set as "Row"
- Version 0.1.0 only support insert/update/delete events. The other events will ignore.
DataFrame:
val spark: SparkSession = ???
val df = spark.readStream.
format("org.apache.spark.sql.mlsql.sources.MLSQLBinLogDataSource").
option("host","127.0.0.1").
option("port","3306").
option("userName","xxxxx").
option("password","xxxxx").
option("databaseNamePattern","xxxxx").
option("tableNamePattern","xxxxx").
load()
df.writeStream.format("delta")....
MLSQL:
set streamName="binlog";
load binlog.`` where
host="127.0.0.1"
and port="3306"
and userName="xxx"
and password="xxxx"
and bingLogNamePrefix="mysql-bin"
and startingOffsets="40000000000004"
and databaseNamePattern="mlsql_console"
and tableNamePattern="script_file"
as table1;