[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-12 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=122256=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-122256
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 12/Jul/18 09:29
Start Date: 12/Jul/18 09:29
Worklog Time Spent: 10m 
  Work Description: iemejia commented on issue #5212: [BEAM-4020] Add 
HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#issuecomment-404450562
 
 
   Thanks for the review and all the orientation around the SDF way @jkff 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 122256)
Time Spent: 4h 40m  (was: 4.5h)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
> Fix For: 2.6.0
>
>  Time Spent: 4h 40m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-12 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=122255=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-122255
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 12/Jul/18 09:28
Start Date: 12/Jul/18 09:28
Worklog Time Spent: 10m 
  Work Description: iemejia closed pull request #5212: [BEAM-4020] Add 
HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseCoderProviderRegistrar.java
 
b/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseCoderProviderRegistrar.java
index f836ebe3551..4127224a75c 100644
--- 
a/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseCoderProviderRegistrar.java
+++ 
b/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseCoderProviderRegistrar.java
@@ -33,6 +33,7 @@
   public List getCoderProviders() {
 return ImmutableList.of(
 HBaseMutationCoder.getCoderProvider(),
-CoderProviders.forCoder(TypeDescriptor.of(Result.class), 
HBaseResultCoder.of()));
+CoderProviders.forCoder(TypeDescriptor.of(Result.class), 
HBaseResultCoder.of()),
+CoderProviders.forCoder(TypeDescriptor.of(HBaseQuery.class), 
HBaseQueryCoder.of()));
   }
 }
diff --git 
a/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java 
b/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java
index 5f04ba18124..9283ed040bb 100644
--- a/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java
+++ b/sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java
@@ -107,6 +107,20 @@
  * .withFilter(filter));
  * }
  *
+ * {@link HBaseIO#readAll()} allows to execute multiple {@link Scan}s to 
multiple {@link Table}s.
+ * These queries are encapsulated via an initial {@link PCollection} of {@link 
HBaseQuery}s and can
+ * be used to create advanced compositional patterns like reading from a 
Source and then based on
+ * the data create new HBase scans.
+ *
+ * Note: {@link HBaseIO.ReadAll} only works with https://beam.apache.org/documentation/runners/capability-matrix/;>runners 
that support
+ * Splittable DoFn.
+ *
+ * {@code
+ * PCollection queries = ...;
+ * queries.apply("readAll", 
HBaseIO.readAll().withConfiguration(configuration));
+ * }
+ *
  * Writing to HBase
  *
  * The HBase sink executes a set of row mutations on a single table. It 
takes as input a {@link
@@ -145,7 +159,6 @@ private HBaseIO() {}
* and a {@link HBaseIO.Read#withTableId tableId} that specifies which table 
to read. A {@link
* Filter} may also optionally be specified using {@link 
HBaseIO.Read#withFilter}.
*/
-  @Experimental
   public static Read read() {
 return new Read(null, "", new SerializableScan(new Scan()));
   }
@@ -219,11 +232,9 @@ private Read(
   } catch (IOException e) {
 LOG.warn("Error checking whether table {} exists; proceeding.", 
tableId, e);
   }
-  return input
-  .getPipeline()
-  .apply(
-  org.apache.beam.sdk.io.Read.from(
-  new HBaseSource(this, null /* estimatedSizeBytes */)));
+
+  return input.apply(
+  org.apache.beam.sdk.io.Read.from(new HBaseSource(this, null /* 
estimatedSizeBytes */)));
 }
 
 @Override
@@ -234,12 +245,16 @@ public void populateDisplayData(DisplayData.Builder 
builder) {
   builder.addIfNotNull(DisplayData.item("scan", 
serializableScan.get().toString()));
 }
 
+public Configuration getConfiguration() {
+  return serializableConfiguration.get();
+}
+
 public String getTableId() {
   return tableId;
 }
 
-public Configuration getConfiguration() {
-  return serializableConfiguration.get();
+public Scan getScan() {
+  return serializableScan.get();
 }
 
 /** Returns the range of keys that will be read from the table. */
@@ -254,6 +269,36 @@ public ByteKeyRange getKeyRange() {
 private final SerializableScan serializableScan;
   }
 
+  /**
+   * A {@link PTransform} that works like {@link #read}, but executes read 
operations coming from a
+   * {@link PCollection} of {@link HBaseQuery}.
+   */
+  public static ReadAll readAll() {
+return new ReadAll(null);
+  }
+
+  /** Implementation of {@link #readAll}. */
+  public static class ReadAll extends PTransform, 
PCollection> {
+
+private ReadAll(SerializableConfiguration serializableConfiguration) {
+  this.serializableConfiguration = serializableConfiguration;
+}
+
+/** Reads from the 

[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=120075=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-120075
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 21:31
Start Date: 06/Jul/18 21:31
Worklog Time Spent: 10m 
  Work Description: iemejia commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200775086
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java
 ##
 @@ -107,6 +107,16 @@
  * .withFilter(filter));
  * }
  *
+ * {@link HBaseIO#readAll()} allows to execute multiple {@link Scan}s to 
multiple {@link Table}s.
 
 Review comment:
   done


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 120075)
Time Spent: 4h 20m  (was: 4h 10m)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 4h 20m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=120073=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-120073
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 21:24
Start Date: 06/Jul/18 21:24
Worklog Time Spent: 10m 
  Work Description: iemejia commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200773277
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseReadSplittableDoFn.java
 ##
 @@ -0,0 +1,116 @@
+/*
+ * 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.hbase;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.range.ByteKey;
+import org.apache.beam.sdk.io.range.ByteKeyRange;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFn.BoundedPerElement;
+import org.apache.beam.sdk.transforms.splittabledofn.ByteKeyRangeTracker;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
+/** A SplittableDoFn to read from HBase. */
+@BoundedPerElement
+class HBaseReadSplittableDoFn extends DoFn {
+  private final SerializableConfiguration serializableConfiguration;
+
+  private transient Connection connection;
+
+  HBaseReadSplittableDoFn(SerializableConfiguration serializableConfiguration) 
{
+this.serializableConfiguration = serializableConfiguration;
+  }
+
+  @Setup
+  public void setup() throws Exception {
+connection = 
ConnectionFactory.createConnection(serializableConfiguration.get());
+  }
+
+  private static Scan newScanInRange(Scan scan, ByteKeyRange range) throws 
IOException {
+return new Scan(scan)
+.setStartRow(range.getStartKey().getBytes())
+.setStopRow(range.getEndKey().getBytes());
+  }
+
+  @ProcessElement
+  public void processElement(ProcessContext c, ByteKeyRangeTracker tracker) 
throws Exception {
+final HBaseQuery query = c.element();
+TableName tableName = TableName.valueOf(query.getTableId());
+Table table = connection.getTable(tableName);
+final ByteKeyRange range = tracker.currentRestriction();
+try (ResultScanner scanner = 
table.getScanner(newScanInRange(query.getScan(), range))) {
+  for (Result result : scanner) {
+ByteKey key = ByteKey.copyFrom(result.getRow());
+if (!tracker.tryClaim(key)) {
+  return;
+}
+c.output(result);
+  }
+  tracker.markDone();
+}
+  }
+
+  @GetInitialRestriction
+  public ByteKeyRange getInitialRestriction(HBaseQuery query) {
+return ByteKeyRange.of(
+ByteKey.copyFrom(query.getScan().getStartRow()),
+ByteKey.copyFrom(query.getScan().getStopRow()));
+  }
+
+  @SplitRestriction
+  public void splitRestriction(
+  HBaseQuery query, ByteKeyRange range, OutputReceiver 
receiver)
+  throws Exception {
+// TODO remove once BEAM-4016 is fixed (lifecycle ignores calling setup 
before splitRestriction)
 
 Review comment:
   Since we seem to have a fix for BEAM-4016 will remove it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 120073)
Time Spent: 4h 10m  (was: 4h)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: 

[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=120030=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-120030
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 21:02
Start Date: 06/Jul/18 21:02
Worklog Time Spent: 10m 
  Work Description: iemejia commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200768714
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseReadSplittableDoFn.java
 ##
 @@ -0,0 +1,116 @@
+/*
+ * 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.hbase;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.range.ByteKey;
+import org.apache.beam.sdk.io.range.ByteKeyRange;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFn.BoundedPerElement;
+import org.apache.beam.sdk.transforms.splittabledofn.ByteKeyRangeTracker;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
+/** A SplittableDoFn to read from HBase. */
+@BoundedPerElement
+class HBaseReadSplittableDoFn extends DoFn {
+  private final SerializableConfiguration serializableConfiguration;
+
+  private transient Connection connection;
+
+  HBaseReadSplittableDoFn(SerializableConfiguration serializableConfiguration) 
{
+this.serializableConfiguration = serializableConfiguration;
+  }
+
+  @Setup
+  public void setup() throws Exception {
+connection = 
ConnectionFactory.createConnection(serializableConfiguration.get());
+  }
+
+  private static Scan newScanInRange(Scan scan, ByteKeyRange range) throws 
IOException {
+return new Scan(scan)
+.setStartRow(range.getStartKey().getBytes())
+.setStopRow(range.getEndKey().getBytes());
+  }
+
+  @ProcessElement
+  public void processElement(ProcessContext c, ByteKeyRangeTracker tracker) 
throws Exception {
+final HBaseQuery query = c.element();
+TableName tableName = TableName.valueOf(query.getTableId());
+Table table = connection.getTable(tableName);
+final ByteKeyRange range = tracker.currentRestriction();
+try (ResultScanner scanner = 
table.getScanner(newScanInRange(query.getScan(), range))) {
+  for (Result result : scanner) {
+ByteKey key = ByteKey.copyFrom(result.getRow());
+if (!tracker.tryClaim(key)) {
+  return;
+}
+c.output(result);
+  }
+  tracker.markDone();
+}
+  }
+
+  @GetInitialRestriction
+  public ByteKeyRange getInitialRestriction(HBaseQuery query) {
+return ByteKeyRange.of(
+ByteKey.copyFrom(query.getScan().getStartRow()),
+ByteKey.copyFrom(query.getScan().getStopRow()));
+  }
+
+  @SplitRestriction
+  public void splitRestriction(
+  HBaseQuery query, ByteKeyRange range, OutputReceiver 
receiver)
+  throws Exception {
+// TODO remove once BEAM-4016 is fixed (lifecycle ignores calling setup 
before splitRestriction)
+setup();
+
+List regionLocations =
+HBaseUtils.getRegionLocations(connection, query.getTableId(), 
query.getScan());
+List splitRanges =
+HBaseUtils.getRanges(regionLocations, query.getTableId(), 
query.getScan());
+if (splitRanges.size() <= 1) {
 
 Review comment:
   If it is zero then we don't have any valid range so I think the if condition 
is useless, good catch. I will remove it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries 

[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119990=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119990
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 19:24
Start Date: 06/Jul/18 19:24
Worklog Time Spent: 10m 
  Work Description: iemejia commented on issue #5212: [BEAM-4020] Add 
HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#issuecomment-403125250
 
 
   Run Java PreCommit


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 119990)
Time Spent: 3h 40m  (was: 3.5h)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 3h 40m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119991=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119991
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 19:24
Start Date: 06/Jul/18 19:24
Worklog Time Spent: 10m 
  Work Description: iemejia removed a comment on issue #5212: [BEAM-4020] 
Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#issuecomment-403125250
 
 
   Run Java PreCommit


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 119991)
Time Spent: 3h 50m  (was: 3h 40m)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 3h 50m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119970=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119970
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 18:31
Start Date: 06/Jul/18 18:31
Worklog Time Spent: 10m 
  Work Description: jkff commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200735397
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseReadSplittableDoFn.java
 ##
 @@ -0,0 +1,116 @@
+/*
+ * 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.hbase;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.range.ByteKey;
+import org.apache.beam.sdk.io.range.ByteKeyRange;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFn.BoundedPerElement;
+import org.apache.beam.sdk.transforms.splittabledofn.ByteKeyRangeTracker;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
+/** A SplittableDoFn to read from HBase. */
+@BoundedPerElement
+class HBaseReadSplittableDoFn extends DoFn {
+  private final SerializableConfiguration serializableConfiguration;
+
+  private transient Connection connection;
+
+  HBaseReadSplittableDoFn(SerializableConfiguration serializableConfiguration) 
{
+this.serializableConfiguration = serializableConfiguration;
+  }
+
+  @Setup
+  public void setup() throws Exception {
+connection = 
ConnectionFactory.createConnection(serializableConfiguration.get());
+  }
+
+  private static Scan newScanInRange(Scan scan, ByteKeyRange range) throws 
IOException {
+return new Scan(scan)
+.setStartRow(range.getStartKey().getBytes())
+.setStopRow(range.getEndKey().getBytes());
+  }
+
+  @ProcessElement
+  public void processElement(ProcessContext c, ByteKeyRangeTracker tracker) 
throws Exception {
+final HBaseQuery query = c.element();
+TableName tableName = TableName.valueOf(query.getTableId());
+Table table = connection.getTable(tableName);
+final ByteKeyRange range = tracker.currentRestriction();
+try (ResultScanner scanner = 
table.getScanner(newScanInRange(query.getScan(), range))) {
+  for (Result result : scanner) {
+ByteKey key = ByteKey.copyFrom(result.getRow());
+if (!tracker.tryClaim(key)) {
+  return;
+}
+c.output(result);
+  }
+  tracker.markDone();
+}
+  }
+
+  @GetInitialRestriction
+  public ByteKeyRange getInitialRestriction(HBaseQuery query) {
+return ByteKeyRange.of(
+ByteKey.copyFrom(query.getScan().getStartRow()),
+ByteKey.copyFrom(query.getScan().getStopRow()));
+  }
+
+  @SplitRestriction
+  public void splitRestriction(
+  HBaseQuery query, ByteKeyRange range, OutputReceiver 
receiver)
+  throws Exception {
+// TODO remove once BEAM-4016 is fixed (lifecycle ignores calling setup 
before splitRestriction)
 
 Review comment:
   Note that if it is fixed, then this code will call setup twice and will leak 
a connection. Please guard against that. Also, does lifecycle call teardown()? 
Also, what if this call is made several times?
   I think it's best to just manually establish a connection here and do 
try-with-resources.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking

[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119971=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119971
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 18:31
Start Date: 06/Jul/18 18:31
Worklog Time Spent: 10m 
  Work Description: jkff commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200736033
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseIO.java
 ##
 @@ -107,6 +107,16 @@
  * .withFilter(filter));
  * }
  *
+ * {@link HBaseIO#readAll()} allows to execute multiple {@link Scan}s to 
multiple {@link Table}s.
 
 Review comment:
   Please add a note that this only works in runners supporting SDF, and link 
to the compatibility matrix.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 119971)
Time Spent: 3h 20m  (was: 3h 10m)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 3h 20m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119972=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119972
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 18:31
Start Date: 06/Jul/18 18:31
Worklog Time Spent: 10m 
  Work Description: jkff commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200735505
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseReadSplittableDoFn.java
 ##
 @@ -0,0 +1,116 @@
+/*
+ * 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.hbase;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.range.ByteKey;
+import org.apache.beam.sdk.io.range.ByteKeyRange;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFn.BoundedPerElement;
+import org.apache.beam.sdk.transforms.splittabledofn.ByteKeyRangeTracker;
+import org.apache.hadoop.hbase.HRegionLocation;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
+/** A SplittableDoFn to read from HBase. */
+@BoundedPerElement
+class HBaseReadSplittableDoFn extends DoFn {
+  private final SerializableConfiguration serializableConfiguration;
+
+  private transient Connection connection;
+
+  HBaseReadSplittableDoFn(SerializableConfiguration serializableConfiguration) 
{
+this.serializableConfiguration = serializableConfiguration;
+  }
+
+  @Setup
+  public void setup() throws Exception {
+connection = 
ConnectionFactory.createConnection(serializableConfiguration.get());
+  }
+
+  private static Scan newScanInRange(Scan scan, ByteKeyRange range) throws 
IOException {
+return new Scan(scan)
+.setStartRow(range.getStartKey().getBytes())
+.setStopRow(range.getEndKey().getBytes());
+  }
+
+  @ProcessElement
+  public void processElement(ProcessContext c, ByteKeyRangeTracker tracker) 
throws Exception {
+final HBaseQuery query = c.element();
+TableName tableName = TableName.valueOf(query.getTableId());
+Table table = connection.getTable(tableName);
+final ByteKeyRange range = tracker.currentRestriction();
+try (ResultScanner scanner = 
table.getScanner(newScanInRange(query.getScan(), range))) {
+  for (Result result : scanner) {
+ByteKey key = ByteKey.copyFrom(result.getRow());
+if (!tracker.tryClaim(key)) {
+  return;
+}
+c.output(result);
+  }
+  tracker.markDone();
+}
+  }
+
+  @GetInitialRestriction
+  public ByteKeyRange getInitialRestriction(HBaseQuery query) {
+return ByteKeyRange.of(
+ByteKey.copyFrom(query.getScan().getStartRow()),
+ByteKey.copyFrom(query.getScan().getStopRow()));
+  }
+
+  @SplitRestriction
+  public void splitRestriction(
+  HBaseQuery query, ByteKeyRange range, OutputReceiver 
receiver)
+  throws Exception {
+// TODO remove once BEAM-4016 is fixed (lifecycle ignores calling setup 
before splitRestriction)
+setup();
+
+List regionLocations =
+HBaseUtils.getRegionLocations(connection, query.getTableId(), 
query.getScan());
+List splitRanges =
+HBaseUtils.getRanges(regionLocations, query.getTableId(), 
query.getScan());
+if (splitRanges.size() <= 1) {
 
 Review comment:
   Can it be 0? If it's 1, then the loop below will work too.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:

[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119950=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119950
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 17:42
Start Date: 06/Jul/18 17:42
Worklog Time Spent: 10m 
  Work Description: iemejia commented on issue #5212: [BEAM-4020] Add 
HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#issuecomment-403101764
 
 
   @jkff I updated multiple things so ready for the second round. Notice that I 
decided better to expose `readAll based on SDF` than use the previous 'withSdf` 
approach. PTAL.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 119950)
Time Spent: 3h 10m  (was: 3h)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 3h 10m
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Work logged] (BEAM-4020) Add HBaseIO.readAll() based on SDF

2018-07-06 Thread ASF GitHub Bot (JIRA)


 [ 
https://issues.apache.org/jira/browse/BEAM-4020?focusedWorklogId=119949=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-119949
 ]

ASF GitHub Bot logged work on BEAM-4020:


Author: ASF GitHub Bot
Created on: 06/Jul/18 17:41
Start Date: 06/Jul/18 17:41
Worklog Time Spent: 10m 
  Work Description: iemejia commented on a change in pull request #5212: 
[BEAM-4020] Add HBaseIO.readAll() based on SDF
URL: https://github.com/apache/beam/pull/5212#discussion_r200723862
 
 

 ##
 File path: 
sdks/java/io/hbase/src/main/java/org/apache/beam/sdk/io/hbase/HBaseReadSplittableDoFn.java
 ##
 @@ -0,0 +1,115 @@
+/*
+ * 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.hbase;
+
+import java.util.List;
+import org.apache.beam.sdk.io.hadoop.SerializableConfiguration;
+import org.apache.beam.sdk.io.range.ByteKey;
+import org.apache.beam.sdk.io.range.ByteKeyRange;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.DoFn.BoundedPerElement;
+import org.apache.beam.sdk.transforms.splittabledofn.ByteKeyRangeTracker;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+
+/** A SplittableDoFn to read from HBase. */
+@BoundedPerElement
+class HBaseReadSplittableDoFn extends DoFn {
+  private final SerializableConfiguration serializableConfiguration;
+  private final String tableId;
+  private final SerializableScan scan;
+
+  private Connection connection;
+
+  HBaseReadSplittableDoFn(
+  SerializableConfiguration serializableConfiguration, String tableId, 
SerializableScan scan) {
+this.serializableConfiguration = serializableConfiguration;
+this.tableId = tableId;
+this.scan = scan;
+  }
+
+  @Setup
+  public void setup() throws Exception {
+if (connection == null) {
+  connection = 
ConnectionFactory.createConnection(serializableConfiguration.get());
+}
+  }
+
+  @ProcessElement
+  public void processElement(ProcessContext c, ByteKeyRangeTracker tracker) 
throws Exception {
+TableName tableName = TableName.valueOf(tableId);
+Table table = connection.getTable(tableName);
+final ByteKeyRange range = tracker.currentRestriction();
+Scan newScan =
 
 Review comment:
   Actually I ended up creating a new entity `HBaseQuery` because Scan does not 
contain the tableId, but the DoFn is now consistent with what  you proposed.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
---

Worklog Id: (was: 119949)
Time Spent: 3h  (was: 2h 50m)

> Add HBaseIO.readAll() based on SDF
> --
>
> Key: BEAM-4020
> URL: https://issues.apache.org/jira/browse/BEAM-4020
> Project: Beam
>  Issue Type: New Feature
>  Components: io-java-hbase
>Reporter: Ismaël Mejía
>Assignee: Ismaël Mejía
>Priority: Minor
>  Time Spent: 3h
>  Remaining Estimate: 0h
>
> Since the support from runners is still limited, it is probably wise to 
> create a first IO based on the current SDF batch implementation in Java to 
> validate/test it with a real data-store. Since HBase partitioning model is 
> quite straightforward it is a perfect candidate.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)