Skip to content

Commit a5076a3

Browse files
committed
Add MariadbDBRecord implementations
UPDATE DOCS
1 parent 9b99eba commit a5076a3

File tree

7 files changed

+208
-72
lines changed

7 files changed

+208
-72
lines changed

mariadb-plugin/docs/Mariadb-batchsink.md

+33-35
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,39 @@ connections.
6060

6161
Data Types Mapping
6262
----------
63-
+--------------------------------+-----------------------+------------------------------------+
64-
| MariaDB Data Type | CDAP Schema Data Type | Comment |
65-
+--------------------------------+-----------------------+------------------------------------+
66-
| TINYINT | int | |
67-
| BOOLEAN, BOOL | boolean | |
68-
| SMALLINT | int | |
69-
| MEDIUMINT | int | |
70-
| INT, INTEGER | int | |
71-
| BIGINT | long | |
72-
| DECIMAL, DEC, NUMERIC, FIXED | decimal | |
73-
| FLOAT | float | |
74-
| DOUBLE, DOUBLE PRECISION, REAL | decimal | |
75-
| BIT | boolean | |
76-
| CHAR | string | |
77-
| VARCHAR | string | |
78-
| BINARY | bytes | |
79-
| CHAR BYTE | bytes | |
80-
| VARBINARY | bytes | |
81-
| TINYBLOB | bytes | |
82-
| BLOB | bytes | |
83-
| MEDIUMBLOB | bytes | |
84-
| LONGBLOB | bytes | |
85-
| TINYTEXT | string | |
86-
| TEXT | string | |
87-
| MEDIUMTEXT | string | |
88-
| LONGTEXT | string | |
89-
| JSON | string | In MariaDB it is alias to LONGTEXT |
90-
| ENUM | string | Mapping to String by default |
91-
| SET | string | |
92-
| DATE | date | |
93-
| TIME | time_micros | |
94-
| DATETIME | timestamp_micros | |
95-
| TIMESTAMP | timestamp_micros | |
96-
| YEAR | date | |
97-
+--------------------------------+-----------------------+------------------------------------+
63+
| MariaDB Data Type | CDAP Schema Data Type | Comment |
64+
|--------------------------------|-----------------------|---------------------------------------------------------|
65+
| TINYINT | int | |
66+
| BOOLEAN, BOOL | boolean | |
67+
| SMALLINT | int | |
68+
| MEDIUMINT | int | |
69+
| INT, INTEGER | int | |
70+
| BIGINT | long | |
71+
| DECIMAL, DEC, NUMERIC, FIXED | decimal | |
72+
| FLOAT | float | |
73+
| DOUBLE, DOUBLE PRECISION, REAL | decimal | |
74+
| BIT | boolean | |
75+
| CHAR | string | |
76+
| VARCHAR | string | |
77+
| BINARY | bytes | |
78+
| CHAR BYTE | bytes | |
79+
| VARBINARY | bytes | |
80+
| TINYBLOB | bytes | |
81+
| BLOB | bytes | |
82+
| MEDIUMBLOB | bytes | |
83+
| LONGBLOB | bytes | |
84+
| TINYTEXT | string | |
85+
| TEXT | string | |
86+
| MEDIUMTEXT | string | |
87+
| LONGTEXT | string | |
88+
| JSON | string | In MariaDB it is alias to LONGTEXT |
89+
| ENUM | string | Mapping to String by default |
90+
| SET | string | |
91+
| DATE | date | |
92+
| TIME | time_micros | |
93+
| DATETIME | timestamp_micros | |
94+
| TIMESTAMP | timestamp_micros | |
95+
| YEAR | int | Users can manually set output schema to map it to Date. |
9896

9997
Example
10098
-------

mariadb-plugin/docs/Mariadb-batchsource.md

+33-37
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,39 @@ with the tradeoff of higher memory usage.
7878

7979
Data Types Mapping
8080
----------
81-
82-
+--------------------------------+-----------------------+------------------------------------+
83-
| MariaDB Data Type | CDAP Schema Data Type | Comment |
84-
+--------------------------------+-----------------------+------------------------------------+
85-
| TINYINT | int | |
86-
| BOOLEAN, BOOL | boolean | |
87-
| SMALLINT | int | |
88-
| MEDIUMINT | int | |
89-
| INT, INTEGER | int | |
90-
| BIGINT | long | |
91-
| DECIMAL, DEC, NUMERIC, FIXED | decimal | |
92-
| FLOAT | float | |
93-
| DOUBLE, DOUBLE PRECISION, REAL | decimal | |
94-
| BIT | boolean | |
95-
| CHAR | string | |
96-
| VARCHAR | string | |
97-
| BINARY | bytes | |
98-
| CHAR BYTE | bytes | |
99-
| VARBINARY | bytes | |
100-
| TINYBLOB | bytes | |
101-
| BLOB | bytes | |
102-
| MEDIUMBLOB | bytes | |
103-
| LONGBLOB | bytes | |
104-
| TINYTEXT | string | |
105-
| TEXT | string | |
106-
| MEDIUMTEXT | string | |
107-
| LONGTEXT | string | |
108-
| JSON | string | In MariaDB it is alias to LONGTEXT |
109-
| ENUM | string | Mapping to String by default |
110-
| SET | string | |
111-
| DATE | date | |
112-
| TIME | time_micros | |
113-
| DATETIME | timestamp_micros | |
114-
| TIMESTAMP | timestamp_micros | |
115-
| YEAR | date | |
116-
+--------------------------------+-----------------------+------------------------------------+
117-
81+
| MariaDB Data Type | CDAP Schema Data Type | Comment |
82+
|--------------------------------|-----------------------|---------------------------------------------------------|
83+
| TINYINT | int | |
84+
| BOOLEAN, BOOL | boolean | |
85+
| SMALLINT | int | |
86+
| MEDIUMINT | int | |
87+
| INT, INTEGER | int | |
88+
| BIGINT | long | |
89+
| DECIMAL, DEC, NUMERIC, FIXED | decimal | |
90+
| FLOAT | float | |
91+
| DOUBLE, DOUBLE PRECISION, REAL | decimal | |
92+
| BIT | boolean | |
93+
| CHAR | string | |
94+
| VARCHAR | string | |
95+
| BINARY | bytes | |
96+
| CHAR BYTE | bytes | |
97+
| VARBINARY | bytes | |
98+
| TINYBLOB | bytes | |
99+
| BLOB | bytes | |
100+
| MEDIUMBLOB | bytes | |
101+
| LONGBLOB | bytes | |
102+
| TINYTEXT | string | |
103+
| TEXT | string | |
104+
| MEDIUMTEXT | string | |
105+
| LONGTEXT | string | |
106+
| JSON | string | In MariaDB it is alias to LONGTEXT |
107+
| ENUM | string | Mapping to String by default |
108+
| SET | string | |
109+
| DATE | date | |
110+
| TIME | time_micros | |
111+
| DATETIME | timestamp_micros | |
112+
| TIMESTAMP | timestamp_micros | |
113+
| YEAR | int | Users can manually set output schema to map it to Date. |
118114

119115
Example
120116
------

mariadb-plugin/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
<version>RELEASE</version>
8484
<scope>compile</scope>
8585
</dependency>
86+
<dependency>
87+
<groupId>io.cdap.plugin</groupId>
88+
<artifactId>mysql-plugin</artifactId>
89+
<version>${project.version}</version>
90+
</dependency>
8691
</dependencies>
8792
<build>
8893
<plugins>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright © 2025 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.cdap.plugin.mariadb;
18+
19+
import io.cdap.cdap.api.data.format.StructuredRecord;
20+
import io.cdap.plugin.db.ColumnType;
21+
import io.cdap.plugin.mysql.MysqlDBRecord;
22+
import java.util.List;
23+
24+
/**
25+
* Writable class for MariaDB Source/Sink.
26+
*/
27+
public class MariadbDBRecord extends MysqlDBRecord {
28+
29+
/**
30+
* Used in map-reduce. Do not remove.
31+
*/
32+
@SuppressWarnings("unused")
33+
public MariadbDBRecord() {
34+
// Required by Hadoop DBRecordReader to create an instance
35+
}
36+
37+
public MariadbDBRecord(StructuredRecord record, List<ColumnType> columnTypes) {
38+
super(record, columnTypes);
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright © 2025 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package io.cdap.plugin.mariadb;
18+
19+
20+
import io.cdap.plugin.mysql.MysqlSchemaReader;
21+
import java.util.Map;
22+
23+
/**
24+
* Schema reader for mapping Maria DB type
25+
*/
26+
public class MariadbSchemaReader extends MysqlSchemaReader {
27+
28+
public MariadbSchemaReader (String sessionID) {
29+
super(sessionID);
30+
}
31+
32+
public MariadbSchemaReader (String sessionID, Map<String, String> connectionArguments) {
33+
super(sessionID, connectionArguments);
34+
}
35+
36+
}

mariadb-plugin/src/main/java/io/cdap/plugin/mariadb/MariadbSink.java

+15
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
import io.cdap.cdap.api.annotation.Description;
2020
import io.cdap.cdap.api.annotation.Name;
2121
import io.cdap.cdap.api.annotation.Plugin;
22+
import io.cdap.cdap.api.data.format.StructuredRecord;
2223
import io.cdap.cdap.etl.api.batch.BatchSink;
24+
import io.cdap.plugin.db.DBRecord;
25+
import io.cdap.plugin.db.SchemaReader;
2326
import io.cdap.plugin.db.config.DBSpecificSinkConfig;
2427
import io.cdap.plugin.db.sink.AbstractDBSink;
2528

29+
import io.cdap.plugin.mysql.MysqlDBRecord;
2630
import java.util.Map;
2731
import javax.annotation.Nullable;
2832

@@ -45,6 +49,17 @@ public MariadbSink(MariadbSinkConfig mariadbSinkConfig) {
4549
this.mariadbSinkConfig = mariadbSinkConfig;
4650
}
4751

52+
@Override
53+
protected DBRecord getDBRecord(StructuredRecord output) {
54+
return new MariadbDBRecord(output, columnTypes);
55+
}
56+
57+
@Override
58+
protected SchemaReader getSchemaReader() {
59+
return new MariadbSchemaReader(null);
60+
}
61+
62+
4863
/**
4964
* MariaDB Sink Config.
5065
*/

0 commit comments

Comments
 (0)