Skip to content

Commit 117cbef

Browse files
Merge pull request #191 from data-integrations/PLUGIN-994
[PLUGIN-994] Adding setFetchSize to the database plugins
2 parents f4109b7 + 749cb0b commit 117cbef

File tree

29 files changed

+640
-278
lines changed

29 files changed

+640
-278
lines changed

aurora-mysql-plugin/widgets/AuroraMysql-batchsource.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
"widget-attributes": {
7474
"default": "1"
7575
}
76+
},
77+
{
78+
"widget-type": "number",
79+
"label": "Fetch Size",
80+
"name": "fetchSize",
81+
"widget-attributes": {
82+
"default": "1000",
83+
"minimum": "0"
84+
}
7685
}
7786
]
7887
},

aurora-postgresql-plugin/widgets/AuroraPostgres-batchsource.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@
7373
"widget-attributes": {
7474
"default": "1"
7575
}
76+
},
77+
{
78+
"widget-type": "number",
79+
"label": "Fetch Size",
80+
"name": "fetchSize",
81+
"widget-attributes": {
82+
"default": "1000",
83+
"minimum": "0"
84+
}
7685
}
7786
]
7887
},

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLSource.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.cdap.plugin.db.batch.source.AbstractDBSource;
3434

3535
import java.util.Collections;
36+
import java.util.HashMap;
3637
import java.util.Map;
3738
import javax.annotation.Nullable;
3839

@@ -101,7 +102,14 @@ public static class CloudSQLMySQLSourceConfig extends AbstractDBSpecificSourceCo
101102

102103
@Override
103104
protected Map<String, String> getDBSpecificArguments() {
104-
return Collections.emptyMap();
105+
if (getFetchSize() == null || getFetchSize() <= 0) {
106+
return Collections.emptyMap();
107+
}
108+
Map<String, String> arguments = new HashMap<>();
109+
// If connected to MySQL > 5.0.2, and setFetchSize() > 0 on a statement,
110+
// statement will use cursor-based fetching to retrieve rows
111+
arguments.put("useCursorFetch", "true");
112+
return arguments;
105113
}
106114

107115
@Override

cloudsql-mysql-plugin/widgets/CloudSQLMySQL-batchsource.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@
147147
"widget-attributes": {
148148
"default": "1"
149149
}
150+
},
151+
{
152+
"widget-type": "number",
153+
"label": "Fetch Size",
154+
"name": "fetchSize",
155+
"widget-attributes": {
156+
"default": "1000",
157+
"minimum": "0"
158+
}
150159
}
151160
]
152161
}

cloudsql-postgresql-plugin/widgets/CloudSQLPostgreSQL-batchsource.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@
147147
"widget-attributes": {
148148
"default": "1"
149149
}
150+
},
151+
{
152+
"widget-type": "number",
153+
"label": "Fetch Size",
154+
"name": "fetchSize",
155+
"widget-attributes": {
156+
"default": "1000",
157+
"minimum": "0"
158+
}
150159
}
151160
]
152161
}

database-commons/src/main/java/io/cdap/plugin/db/ConnectionConfigAccessor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ConnectionConfigAccessor {
3636
private static final String CONNECTION_ARGUMENTS = "io.cdap.plugin.db.connection.arguments";
3737
private static final String INIT_QUERIES = "io.cdap.plugin.db.init.queries";
3838
public static final String AUTO_COMMIT_ENABLED = "io.cdap.plugin.db.output.autocommit.enabled";
39+
public static final String FETCH_SIZE = "io.cdap.plugin.db.fetch.size";
3940

4041
private static final Gson GSON = new Gson();
4142
private static final Type STRING_MAP_TYPE = new TypeToken<Map<String, String>>() { }.getType();
@@ -99,6 +100,14 @@ public boolean isAutoCommitEnabled() {
99100
return configuration.getBoolean(AUTO_COMMIT_ENABLED, false);
100101
}
101102

103+
public void setFetchSize(Integer fetchSize) {
104+
configuration.setInt(FETCH_SIZE, fetchSize);
105+
}
106+
107+
public Integer getFetchSize() {
108+
return configuration.getInt(FETCH_SIZE, 0);
109+
}
110+
102111
public Configuration getConfiguration() {
103112
return configuration;
104113
}

0 commit comments

Comments
 (0)