[
https://issues.apache.org/jira/browse/BEAM-10136?focusedWorklogId=457526&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-457526
]
ASF GitHub Bot logged work on BEAM-10136:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 11/Jul/20 05:12
Start Date: 11/Jul/20 05:12
Worklog Time Spent: 10m
Work Description: piotr-szuberski commented on a change in pull request
#12145:
URL: https://github.com/apache/beam/pull/12145#discussion_r453157075
##########
File path:
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/external/JdbcExternalWrite.java
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.jdbc.external;
+
+import com.google.auto.service.AutoService;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+import java.util.Map;
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.annotations.Experimental.Kind;
+import org.apache.beam.sdk.expansion.ExternalTransformRegistrar;
+import org.apache.beam.sdk.io.jdbc.JdbcIO;
+import org.apache.beam.sdk.io.jdbc.JdbcIO.DataSourceConfiguration;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.ExternalTransformBuilder;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PDone;
+import org.apache.beam.sdk.values.Row;
+import
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+
+/** Exposes {@link JdbcIO.Write} as an external transform for cross-language
usage. */
+@Experimental(Kind.PORTABILITY)
+@AutoService(ExternalTransformRegistrar.class)
+public class JdbcExternalWrite implements ExternalTransformRegistrar {
+
+ public static final String URN = "beam:external:java:jdbc:write:v1";
+
+ @Override
+ public Map<String, Class<? extends ExternalTransformBuilder>>
knownBuilders() {
+ return ImmutableMap.of(URN, JdbcExternalWrite.Builder.class);
+ }
+
+ /** Parameters class to expose the Write transform to an external SDK. */
+ public static class WriteConfiguration extends Configuration {
+ private String statement;
+
+ public void setStatement(String statement) {
+ this.statement = statement;
+ }
+ }
+
+ public static class Builder
+ implements ExternalTransformBuilder<WriteConfiguration,
PCollection<Row>, PDone> {
+ @Override
+ public PTransform<PCollection<Row>, PDone>
buildExternal(WriteConfiguration configuration) {
+ DataSourceConfiguration dataSourceConfiguration =
configuration.getDataSourceConfiguration();
+
+ // TODO: BEAM-10396 use writeRows() when it's available
+ return JdbcIO.<Row>write()
+ .withDataSourceConfiguration(dataSourceConfiguration)
+ .withStatement(configuration.statement)
+ .withPreparedStatementSetter(new XlangPreparedStatementSetter());
+ }
+
+ private static class XlangPreparedStatementSetter
+ implements JdbcIO.PreparedStatementSetter<Row> {
+ @Override
+ public void setParameters(Row row, PreparedStatement statement) throws
SQLException {
+ List<Schema.Field> fieldTypes = row.getSchema().getFields();
+ for (int i = 0; i < fieldTypes.size(); ++i) {
+ Schema.TypeName typeName = fieldTypes.get(i).getType().getTypeName();
+ switch (typeName) {
+ case DATETIME:
Review comment:
@chamikaramj I'll do a separate PR for this on Monday. I don't get how
should I deal with such PRs that depend on each other? I'm used to Gerrit where
every commit is a separate PR rebased on the previous commit. But here it would
be a duplicate PR with one more commit. Is that ok or there is a smarter way to
publish a PR based on the changes that are not merged yet and reviewed in
another PR?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 457526)
Time Spent: 21h 10m (was: 21h)
> Add cross-language wrapper for Java's JdbcIO Write
> --------------------------------------------------
>
> Key: BEAM-10136
> URL: https://issues.apache.org/jira/browse/BEAM-10136
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Affects Versions: Not applicable
> Reporter: Piotr Szuberski
> Assignee: Piotr Szuberski
> Priority: P2
> Labels: portability
> Fix For: Not applicable
>
> Time Spent: 21h 10m
> Remaining Estimate: 0h
>
> Add cross-language wrapper for Java's Jdbc Write
--
This message was sent by Atlassian Jira
(v8.3.4#803005)