Zhangyx39 commented on a change in pull request #986: SAMZA-2156: Couchbase 
support for Samza Table API
URL: https://github.com/apache/samza/pull/986#discussion_r276421219
 
 

 ##########
 File path: 
samza-kv-remote/src/main/java/org/apache/samza/table/remote/couchbase/CouchbaseTableWriteFunction.java
 ##########
 @@ -0,0 +1,103 @@
+/*
+ * 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.samza.table.remote.couchbase;
+
+import com.couchbase.client.deps.io.netty.buffer.Unpooled;
+import com.couchbase.client.java.document.BinaryDocument;
+import com.couchbase.client.java.document.Document;
+import com.couchbase.client.java.document.JsonDocument;
+import com.couchbase.client.java.document.json.JsonObject;
+import com.google.common.base.Preconditions;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.samza.SamzaException;
+import org.apache.samza.context.Context;
+import org.apache.samza.table.remote.TableWriteFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Single;
+import rx.SingleSubscriber;
+
+/**
+ * TableWriteFunction implementation for writing to Couchbase. The value type 
can be either {@link JsonObject} or
+ * any other Object. If the value type is JsonObject, data will be stored in 
Couchbase in JSON format, which can be
+ * queried with N1QL. Otherwise, a {@link org.apache.samza.serializers.Serde} 
needs to be provided to serialize and
+ * deserialize the value object.
+ * @param <V> Type of values to write to Couchbase
+ */
+public class CouchbaseTableWriteFunction<V> extends 
BaseCouchbaseTableFunction<V>
+    implements TableWriteFunction<String, V> {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(CouchbaseTableWriteFunction.class);
+
+  /**
+   * Construct an instance of {@link CouchbaseTableWriteFunction}.
+   * @param bucketName Name of the couchbase bucket
+   * @param clusterNodes Some Hosts of the Couchbase cluster. Recommended to 
provide more than one nodes so that if
+   *                     the first node could not be connected, other nodes 
can be tried.
+   * @param valueClass Type of values
+   */
+  public CouchbaseTableWriteFunction(String bucketName, Class<V> valueClass, 
String... clusterNodes) {
+    super(bucketName, valueClass, clusterNodes);
+  }
+
+  @Override
+  public void init(Context context) {
+    super.init(context);
+    LOGGER.info("Write function for bucket {} initialized successfully", 
bucketName);
+  }
+
+  @Override
+  public CompletableFuture<Void> putAsync(String key, V record) {
+    Preconditions.checkNotNull(key);
+    Preconditions.checkArgument(!key.contains(" "), "key must not contain 
spaces.");
 
 Review comment:
   Right. Empty string is also not valid. Should check this.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to