com.couchbase.spark.japi.CouchbaseSparkContext Maven / Gradle / Ivy
/*
* Copyright (c) 2015 Couchbase, Inc.
*
* Licensed 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 com.couchbase.spark.japi;
import com.couchbase.client.java.analytics.AnalyticsQuery;
import com.couchbase.client.java.document.Document;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.view.SpatialViewQuery;
import com.couchbase.client.java.view.ViewQuery;
import com.couchbase.spark.connection.*;
import com.couchbase.spark.rdd.*;
import org.apache.spark.SparkContext;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.concurrent.duration.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class CouchbaseSparkContext {
private final SparkContext sc;
protected CouchbaseSparkContext(SparkContext sc) {
this.sc = sc;
}
public static CouchbaseSparkContext couchbaseContext(SparkContext sc) {
return new CouchbaseSparkContext(sc);
}
public static CouchbaseSparkContext couchbaseContext(JavaSparkContext sc) {
return new CouchbaseSparkContext(sc.sc());
}
public JavaRDD couchbaseGet(List ids, String bucket) {
return couchbaseGet(ids, bucket, JsonDocument.class);
}
public JavaRDD couchbaseGet(List ids) {
return couchbaseGet(ids, null, JsonDocument.class);
}
public JavaRDD couchbaseGet(List ids, Class clazz) {
return couchbaseGet(ids, null, clazz);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseGet(List ids, String bucket, Class clazz) {
return new KeyValueRDD(
sc,
SparkUtil.listToSeq(ids),
bucket,
scala.Option.apply(null),
SparkUtil.classTag(clazz)
).toJavaRDD();
}
public JavaRDD couchbaseGet(List ids, String bucket, long timeout) {
return couchbaseGet(ids, bucket, JsonDocument.class, timeout);
}
public JavaRDD couchbaseGet(List ids, long timeout) {
return couchbaseGet(ids, null, JsonDocument.class, timeout);
}
public JavaRDD couchbaseGet(List ids, Class clazz, long timeout) {
return couchbaseGet(ids, null, clazz, timeout);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseGet(List ids, String bucket, Class clazz, long timeout) {
return new KeyValueRDD(
sc,
SparkUtil.listToSeq(ids),
bucket,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS)),
SparkUtil.classTag(clazz)
).toJavaRDD();
}
public JavaRDD couchbaseSubdocLookup(List ids, List get) {
return couchbaseSubdocLookup(ids, get, Collections.emptyList(), null);
}
public JavaRDD couchbaseSubdocLookup(List ids, List get, List exists) {
return couchbaseSubdocLookup(ids, get, exists, null);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocLookup(List ids, List get, List exists,
String bucket) {
List specs = new ArrayList(ids.size());
for (String id : ids) {
specs.add(new SubdocLookupSpec(id, SparkUtil.listToSeq(get), SparkUtil.listToSeq(exists)));
}
return new SubdocLookupRDD(
sc,
SparkUtil.listToSeq(specs),
bucket,
scala.Option.apply(null)
).toJavaRDD();
}
public JavaRDD couchbaseSubdocLookup(List ids, List get, long timeout) {
return couchbaseSubdocLookup(ids, get, Collections.emptyList(), null, timeout);
}
public JavaRDD couchbaseSubdocLookup(List ids, List get, List exists, long timeout) {
return couchbaseSubdocLookup(ids, get, exists, null, timeout);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocLookup(List ids, List get, List exists,
String bucket, long timeout) {
List specs = new ArrayList(ids.size());
for (String id : ids) {
specs.add(new SubdocLookupSpec(id, SparkUtil.listToSeq(get), SparkUtil.listToSeq(exists)));
}
return new SubdocLookupRDD(
sc,
SparkUtil.listToSeq(specs),
bucket,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS))
).toJavaRDD();
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocMutate(List specs) {
return couchbaseSubdocMutate(specs, null);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocMutate(List specs, String bucket) {
return new SubdocMutateRDD(
sc,
SparkUtil.listToSeq(specs),
bucket,
scala.Option.apply(null)
).toJavaRDD();
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocMutate(List specs, long timeout) {
return couchbaseSubdocMutate(specs, null, timeout);
}
@SuppressWarnings({"unchecked"})
public JavaRDD couchbaseSubdocMutate(List specs, String bucket, long timeout) {
return new SubdocMutateRDD(
sc,
SparkUtil.listToSeq(specs),
bucket,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS))
).toJavaRDD();
}
public JavaRDD couchbaseView(final ViewQuery query) {
return couchbaseView(query, null);
}
public JavaRDD couchbaseView(final ViewQuery query, long timeout) {
return couchbaseView(query, null, timeout);
}
public JavaRDD couchbaseView(final ViewQuery query, final String bucket) {
return new ViewRDD(sc, query, bucket, scala.Option.apply(null), null).toJavaRDD();
}
public JavaRDD couchbaseView(final ViewQuery query, final String bucket, long timeout) {
return new ViewRDD(sc, query, bucket,
scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS)),
null).toJavaRDD();
}
public JavaRDD couchbaseSpatialView(final SpatialViewQuery query) {
return couchbaseSpatialView(query, null);
}
public JavaRDD couchbaseSpatialView(final SpatialViewQuery query, final String bucket) {
return new SpatialViewRDD(sc, query, bucket, scala.Option.apply(null)).toJavaRDD();
}
public JavaRDD couchbaseSpatialView(final SpatialViewQuery query, long timeout) {
return couchbaseSpatialView(query, null, timeout);
}
public JavaRDD couchbaseSpatialView(final SpatialViewQuery query, final String bucket, long timeout) {
return new SpatialViewRDD(sc, query, bucket, scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS))).toJavaRDD();
}
public JavaRDD couchbaseQuery(final N1qlQuery query) {
return couchbaseQuery(query, null);
}
public JavaRDD couchbaseQuery(final N1qlQuery query, final String bucket) {
return new QueryRDD(sc, query, bucket, scala.Option.apply(null)).toJavaRDD();
}
public JavaRDD couchbaseQuery(final N1qlQuery query, long timeout) {
return couchbaseQuery(query, null, timeout);
}
public JavaRDD couchbaseQuery(final N1qlQuery query, final String bucket, long timeout) {
return new QueryRDD(sc, query, bucket, scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS))).toJavaRDD();
}
public JavaRDD couchbaseAnalytics(final AnalyticsQuery query) {
return couchbaseAnalytics(query, null);
}
public JavaRDD couchbaseAnalytics(final AnalyticsQuery query, final String bucket) {
return new AnalyticsRDD(sc, query, bucket, scala.Option.apply(null)).toJavaRDD();
}
public JavaRDD couchbaseAnalytics(final AnalyticsQuery query, long timeout) {
return couchbaseAnalytics(query, null, timeout);
}
public JavaRDD couchbaseAnalytics(final AnalyticsQuery query, final String bucket, long timeout) {
return new AnalyticsRDD(sc, query, bucket, scala.Option.apply(Duration.create(timeout, TimeUnit.MILLISECONDS))).toJavaRDD();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy