http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/index/RyaSecondaryIndexer.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/index/RyaSecondaryIndexer.java b/common/rya.api/src/main/java/mvm/rya/api/persist/index/RyaSecondaryIndexer.java deleted file mode 100644 index 8c827c1..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/index/RyaSecondaryIndexer.java +++ /dev/null @@ -1,45 +0,0 @@ -package mvm.rya.api.persist.index; - -/* - * 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. - */ - - -import java.io.Closeable; -import java.io.Flushable; -import java.io.IOException; -import java.util.Collection; - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaURI; - -import org.apache.hadoop.conf.Configurable; - -public interface RyaSecondaryIndexer extends Closeable, Flushable, Configurable { - - public String getTableName(); - - public void storeStatements(Collection<RyaStatement> statements) throws IOException; - - public void storeStatement(RyaStatement statement) throws IOException; - - public void deleteStatement(RyaStatement stmt) throws IOException; - - public void dropGraph(RyaURI... graphs); - -}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/joinselect/SelectivityEvalDAO.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/joinselect/SelectivityEvalDAO.java b/common/rya.api/src/main/java/mvm/rya/api/persist/joinselect/SelectivityEvalDAO.java deleted file mode 100644 index 28f797b..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/joinselect/SelectivityEvalDAO.java +++ /dev/null @@ -1,37 +0,0 @@ -package mvm.rya.api.persist.joinselect; - -/* - * 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. - */ - - - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.persist.RdfEvalStatsDAO; -import org.openrdf.query.algebra.StatementPattern; -import org.openrdf.query.algebra.TupleExpr; - -public interface SelectivityEvalDAO<C extends RdfCloudTripleStoreConfiguration> extends RdfEvalStatsDAO<C> { - - public double getJoinSelect(C conf, TupleExpr te1, TupleExpr te2) throws Exception; - - public long getCardinality(C conf, StatementPattern sp) throws Exception; - - public int getTableSize(C conf) throws Exception; - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/BatchRyaQuery.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/BatchRyaQuery.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/BatchRyaQuery.java deleted file mode 100644 index 113ce51..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/BatchRyaQuery.java +++ /dev/null @@ -1,115 +0,0 @@ -package mvm.rya.api.persist.query; - -/* - * 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. - */ - - - -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaStatement; - -/** - * Query domain object contains the query to run as a {@link mvm.rya.api.domain.RyaStatement} and options for running the query - */ -public class BatchRyaQuery extends RyaQueryOptions { - - //queries - private Iterable<RyaStatement> queries; - - //maximum number of ranges before we use a batchScanner - private int maxRanges = 2; - - public BatchRyaQuery(Iterable<RyaStatement> queries) { - Preconditions.checkNotNull(queries, "RyaStatement queries cannot be null"); - this.queries = queries; - } - - public static RyaBatchQueryBuilder builder(Iterable<RyaStatement> queries) { - return new RyaBatchQueryBuilder(queries); - } - - public static class RyaBatchQueryBuilder extends RyaOptionsBuilder<RyaBatchQueryBuilder> { - private BatchRyaQuery ryaQuery; - - public RyaBatchQueryBuilder(Iterable<RyaStatement> queries) { - this(new BatchRyaQuery(queries)); - } - - public RyaBatchQueryBuilder(BatchRyaQuery query) { - super(query); - this.ryaQuery = query; - } - - public RyaBatchQueryBuilder setMaxRanges(int maxRanges) { - ryaQuery.setMaxRanges(maxRanges); - return this; - } - - public BatchRyaQuery build() { - return ryaQuery; - } - } - - public Iterable<RyaStatement> getQueries() { - return queries; - } - - public void setQueries(Iterable<RyaStatement> queries) { - this.queries = queries; - } - - public int getMaxRanges() { - return maxRanges; - } - - public void setMaxRanges(int maxRanges) { - this.maxRanges = maxRanges; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - BatchRyaQuery that = (BatchRyaQuery) o; - - if (queries != null ? !queries.equals(that.queries) : that.queries != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (queries != null ? queries.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "BatchRyaQuery{" + - "queries=" + Iterables.toString(queries) + - "options={" + super.toString() + - '}' + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQuery.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQuery.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQuery.java deleted file mode 100644 index 5235989..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQuery.java +++ /dev/null @@ -1,97 +0,0 @@ -package mvm.rya.api.persist.query; - -/* - * 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. - */ - - - -import com.google.common.base.Preconditions; -import mvm.rya.api.domain.RyaStatement; - -/** - * Query domain object contains the query to run as a {@link RyaStatement} and options for running the query - */ -public class RyaQuery extends RyaQueryOptions { - - //query - private RyaStatement query; - - public RyaQuery(RyaStatement query) { - Preconditions.checkNotNull(query, "RyaStatement query cannot be null"); - this.query = query; - } - - public static RyaQueryBuilder builder(RyaStatement query) { - return new RyaQueryBuilder(query); - } - - public static class RyaQueryBuilder extends RyaOptionsBuilder<RyaQueryBuilder> { - private RyaQuery ryaQuery; - - public RyaQueryBuilder(RyaStatement query) { - this(new RyaQuery(query)); - } - - public RyaQueryBuilder(RyaQuery query) { - super(query); - this.ryaQuery = query; - } - - public RyaQuery build() { - return ryaQuery; - } - } - - public RyaStatement getQuery() { - return query; - } - - public void setQuery(RyaStatement query) { - this.query = query; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - - RyaQuery ryaQuery = (RyaQuery) o; - - if (query != null ? !query.equals(ryaQuery.query) : ryaQuery.query != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + (query != null ? query.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "RyaQuery{" + - "query=" + query + - "options={" + super.toString() + - '}' + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryEngine.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryEngine.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryEngine.java deleted file mode 100644 index 7454eea..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryEngine.java +++ /dev/null @@ -1,96 +0,0 @@ -package mvm.rya.api.persist.query; - -/* - * 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. - */ - - - -import info.aduna.iteration.CloseableIteration; - -import java.util.Collection; -import java.util.Map; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaConfigured; -import mvm.rya.api.persist.RyaDAOException; - -import org.calrissian.mango.collect.CloseableIterable; -import org.openrdf.query.BindingSet; - -/** - * Rya Query Engine to perform queries against the Rya triple store. - * <p/> - * Date: 7/17/12 - * Time: 8:25 AM - */ -public interface RyaQueryEngine<C extends RdfCloudTripleStoreConfiguration> extends RyaConfigured<C> { - - /** - * Query the Rya store using the RyaStatement. The Configuration object provides information such as auths, ttl, etc - * - * @param stmt - * @param conf - * @return - * @throws RyaDAOException - * @deprecated - */ - public CloseableIteration<RyaStatement, RyaDAOException> query(RyaStatement stmt, C conf) throws RyaDAOException; - - /** - * Batch query - * - * @param stmts - * @param conf - * @return - * @throws RyaDAOException - */ - public CloseableIteration<? extends Map.Entry<RyaStatement, BindingSet>, RyaDAOException> - queryWithBindingSet(Collection<Map.Entry<RyaStatement, BindingSet>> stmts, C conf) throws RyaDAOException; - - /** - * Performs intersection joins. - * - * @param stmts - * @param conf - * @return - * @throws RyaDAOException - * @deprecated - */ - public CloseableIteration<RyaStatement, RyaDAOException> batchQuery(Collection<RyaStatement> stmts, C conf) throws RyaDAOException; - - /** - * Query with a {@link} RyaQuery. A single query that will return a {@link CloseableIterable} of RyaStatements - * - * @param ryaQuery - * @return - * @throws RyaDAOException - */ - public CloseableIterable<RyaStatement> query(RyaQuery ryaQuery) throws RyaDAOException; - - /** - * Run a batch rya query - * - * @param batchRyaQuery - * @return - * @throws RyaDAOException - */ - public CloseableIterable<RyaStatement> query(BatchRyaQuery batchRyaQuery) throws RyaDAOException; - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryOptions.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryOptions.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryOptions.java deleted file mode 100644 index c77796e..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/RyaQueryOptions.java +++ /dev/null @@ -1,246 +0,0 @@ -package mvm.rya.api.persist.query; - -/* - * 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. - */ - - - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; - -/** - */ -public class RyaQueryOptions { - private static final Logger logger = LoggerFactory.getLogger(RyaQueryOptions.class); - //options - protected String[] auths; - protected Long ttl; - protected Long currentTime; - protected Long maxResults; - protected Integer numQueryThreads = 4; - protected Integer batchSize = 1000; - protected String regexSubject; - protected String regexPredicate; - protected String regexObject; - protected RdfCloudTripleStoreConfiguration conf; - - public static class RyaOptionsBuilder<T extends RyaOptionsBuilder> { - private RyaQueryOptions options; - - public RyaOptionsBuilder(RyaQueryOptions query) { - this.options = query; - } - - public T load(RdfCloudTripleStoreConfiguration conf) { - options.setConf(conf); - return (T) this.setAuths(conf.getAuths()) - .setBatchSize(conf.getBatchSize()) - .setCurrentTime(conf.getStartTime()) - .setMaxResults(conf.getLimit()) - .setNumQueryThreads(conf.getNumThreads()) - .setRegexObject(conf.getRegexObject()) - .setRegexPredicate(conf.getRegexPredicate()) - .setRegexSubject(conf.getRegexSubject()) - .setTtl(conf.getTtl()); - } - - public T setAuths(String[] auths) { - options.setAuths(auths); - return (T) this; - } - - public T setRegexObject(String regexObject) { - options.setRegexObject(regexObject); - return (T) this; - } - - public T setRegexPredicate(String regexPredicate) { - options.setRegexPredicate(regexPredicate); - return (T) this; - } - - public T setRegexSubject(String regexSubject) { - options.setRegexSubject(regexSubject); - return (T) this; - } - - public T setBatchSize(Integer batchSize) { - options.setBatchSize(batchSize); - return (T) this; - } - - public T setNumQueryThreads(Integer numQueryThreads) { - options.setNumQueryThreads(numQueryThreads); - return (T) this; - } - - public T setMaxResults(Long maxResults) { - options.setMaxResults(maxResults); - return (T) this; - } - - public T setCurrentTime(Long currentTime) { - options.setCurrentTime(currentTime); - return (T) this; - } - - public T setTtl(Long ttl) { - options.setTtl(ttl); - return (T) this; - } - } - - public RdfCloudTripleStoreConfiguration getConf() { - return conf; - } - - public void setConf(RdfCloudTripleStoreConfiguration conf) { - this.conf = conf; - } - - public Long getTtl() { - return ttl; - } - - public void setTtl(Long ttl) { - this.ttl = ttl; - } - - public Long getCurrentTime() { - return currentTime; - } - - public void setCurrentTime(Long currentTime) { - this.currentTime = currentTime; - } - - public Integer getNumQueryThreads() { - return numQueryThreads; - } - - public void setNumQueryThreads(Integer numQueryThreads) { - this.numQueryThreads = numQueryThreads; - } - - public Long getMaxResults() { - return maxResults; - } - - public void setMaxResults(Long maxResults) { - this.maxResults = maxResults; - } - - public Integer getBatchSize() { - return batchSize; - } - - public void setBatchSize(Integer batchSize) { - this.batchSize = batchSize; - } - - public String getRegexSubject() { - return regexSubject; - } - - public void setRegexSubject(String regexSubject) { - this.regexSubject = regexSubject; - } - - public String getRegexPredicate() { - return regexPredicate; - } - - public void setRegexPredicate(String regexPredicate) { - this.regexPredicate = regexPredicate; - } - - public String getRegexObject() { - return regexObject; - } - - public void setRegexObject(String regexObject) { - this.regexObject = regexObject; - } - - public String[] getAuths() { - return auths; - } - - public void setAuths(String[] auths) { - if (auths == null) { - this.auths = new String[0]; - } else { - this.auths = auths.clone(); - } - } - - @Override - public String toString() { - return "RyaQueryOptions{" + - "auths=" + (auths == null ? null : Arrays.asList(auths)) + - ", ttl=" + ttl + - ", currentTime=" + currentTime + - ", maxResults=" + maxResults + - ", numQueryThreads=" + numQueryThreads + - ", batchSize=" + batchSize + - ", regexSubject='" + regexSubject + '\'' + - ", regexPredicate='" + regexPredicate + '\'' + - ", regexObject='" + regexObject + '\'' + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - RyaQueryOptions that = (RyaQueryOptions) o; - - if (!Arrays.equals(auths, that.auths)) return false; - if (batchSize != null ? !batchSize.equals(that.batchSize) : that.batchSize != null) return false; - if (currentTime != null ? !currentTime.equals(that.currentTime) : that.currentTime != null) return false; - if (maxResults != null ? !maxResults.equals(that.maxResults) : that.maxResults != null) return false; - if (numQueryThreads != null ? !numQueryThreads.equals(that.numQueryThreads) : that.numQueryThreads != null) - return false; - if (regexObject != null ? !regexObject.equals(that.regexObject) : that.regexObject != null) return false; - if (regexPredicate != null ? !regexPredicate.equals(that.regexPredicate) : that.regexPredicate != null) - return false; - if (regexSubject != null ? !regexSubject.equals(that.regexSubject) : that.regexSubject != null) return false; - if (ttl != null ? !ttl.equals(that.ttl) : that.ttl != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = auths != null ? Arrays.hashCode(auths) : 0; - result = 31 * result + (ttl != null ? ttl.hashCode() : 0); - result = 31 * result + (currentTime != null ? currentTime.hashCode() : 0); - result = 31 * result + (maxResults != null ? maxResults.hashCode() : 0); - result = 31 * result + (numQueryThreads != null ? numQueryThreads.hashCode() : 0); - result = 31 * result + (batchSize != null ? batchSize.hashCode() : 0); - result = 31 * result + (regexSubject != null ? regexSubject.hashCode() : 0); - result = 31 * result + (regexPredicate != null ? regexPredicate.hashCode() : 0); - result = 31 * result + (regexObject != null ? regexObject.hashCode() : 0); - return result; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/HashJoin.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/HashJoin.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/HashJoin.java deleted file mode 100644 index 286ea7a..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/HashJoin.java +++ /dev/null @@ -1,158 +0,0 @@ -package mvm.rya.api.persist.query.join; - -/* - * 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. - */ - - - -import info.aduna.iteration.CloseableIteration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.query.RyaQueryEngine; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.utils.EnumerationWrapper; - -import java.util.Enumeration; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Use HashTable to do a HashJoin. - * <p/> - * TODO: Somehow make a more streaming way of doing this hash join. This will not support large sets. - * Date: 7/26/12 - * Time: 8:58 AM - */ -public class HashJoin<C extends RdfCloudTripleStoreConfiguration> implements Join<C> { - - private RyaContext ryaContext = RyaContext.getInstance(); - private RyaQueryEngine ryaQueryEngine; - - public HashJoin() { - } - - public HashJoin(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } - - @Override - public CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) throws RyaDAOException { - ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer> ht = new ConcurrentHashMap<Map.Entry<RyaURI, RyaType>, Integer>(); - int count = 0; - boolean first = true; - for (RyaURI pred : preds) { - count++; - //query - CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, null), null); - //add to hashtable - while (results.hasNext()) { - RyaStatement next = results.next(); - RyaURI subject = next.getSubject(); - RyaType object = next.getObject(); - Map.Entry<RyaURI, RyaType> entry = new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(subject, object); - if (!first) { - if (!ht.containsKey(entry)) { - continue; //not in join - } - } - ht.put(entry, count); - } - //remove from hashtable values that are under count - if (first) { - first = false; - } else { - for (Map.Entry<Map.Entry<RyaURI, RyaType>, Integer> entry : ht.entrySet()) { - if (entry.getValue() < count) { - ht.remove(entry.getKey()); - } - } - } - } - final Enumeration<Map.Entry<RyaURI, RyaType>> keys = ht.keys(); - return new CloseableIteration<RyaStatement, RyaDAOException>() { - @Override - public void close() throws RyaDAOException { - - } - - @Override - public boolean hasNext() throws RyaDAOException { - return keys.hasMoreElements(); - } - - @Override - public RyaStatement next() throws RyaDAOException { - Map.Entry<RyaURI, RyaType> subjObj = keys.nextElement(); - return new RyaStatement(subjObj.getKey(), null, subjObj.getValue()); - } - - @Override - public void remove() throws RyaDAOException { - keys.nextElement(); - } - }; - } - - @Override - public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) throws RyaDAOException { - ConcurrentHashMap<RyaURI, Integer> ht = new ConcurrentHashMap<RyaURI, Integer>(); - int count = 0; - boolean first = true; - for (Map.Entry<RyaURI, RyaType> predObj : predObjs) { - count++; - RyaURI pred = predObj.getKey(); - RyaType obj = predObj.getValue(); - //query - CloseableIteration<RyaStatement, RyaDAOException> results = ryaQueryEngine.query(new RyaStatement(null, pred, obj), null); - //add to hashtable - while (results.hasNext()) { - RyaURI subject = results.next().getSubject(); - if (!first) { - if (!ht.containsKey(subject)) { - continue; //not in join - } - } - ht.put(subject, count); - } - //remove from hashtable values that are under count - if (first) { - first = false; - } else { - for (Map.Entry<RyaURI, Integer> entry : ht.entrySet()) { - if (entry.getValue() < count) { - ht.remove(entry.getKey()); - } - } - } - } - return new EnumerationWrapper<RyaURI, RyaDAOException>(ht.keys()); - } - - public RyaQueryEngine getRyaQueryEngine() { - return ryaQueryEngine; - } - - public void setRyaQueryEngine(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/IterativeJoin.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/IterativeJoin.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/IterativeJoin.java deleted file mode 100644 index 3cb48a5..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/IterativeJoin.java +++ /dev/null @@ -1,233 +0,0 @@ -package mvm.rya.api.persist.query.join; - -/* - * 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. - */ - - - -import com.google.common.base.Preconditions; -import info.aduna.iteration.CloseableIteration; -import info.aduna.iteration.ConvertingIteration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.*; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.query.RyaQueryEngine; -import mvm.rya.api.resolver.RyaContext; -import org.openrdf.query.BindingSet; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - -/** - * Date: 7/24/12 - * Time: 8:52 AM - */ -public class IterativeJoin<C extends RdfCloudTripleStoreConfiguration> implements Join<C> { - - private RyaContext ryaContext = RyaContext.getInstance(); - private RyaQueryEngine ryaQueryEngine; - - public IterativeJoin() { - } - - public IterativeJoin(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } - - /** - * Return all statements that have input predicates. Predicates must not be null or ranges - * - * @param preds - * @return - */ - @Override - public CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) - throws RyaDAOException { - Preconditions.checkNotNull(preds); - Preconditions.checkArgument(preds.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics - - CloseableIteration<RyaStatement, RyaDAOException> iter = null; - for (RyaURI pred : preds) { - if (iter == null) { - iter = ryaQueryEngine.query(new RyaStatement(null, pred, null), null); - } else { - iter = join(iter, pred); - } - } - - return iter; - } - - /** - * Return all subjects that have the predicate objects associated. Predicate and objects must be not null or ranges - * to ensure sorting - * - * @param predObjs - * @return - * @throws mvm.rya.api.persist.RyaDAOException - * - */ - @Override - public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) - throws RyaDAOException { - Preconditions.checkNotNull(predObjs); - Preconditions.checkArgument(predObjs.length > 1, "Must join 2 or more"); - - //TODO: Reorder predObjs based on statistics - CloseableIteration<RyaStatement, RyaDAOException> first = null; - CloseableIteration<RyaURI, RyaDAOException> iter = null; - for (Map.Entry<RyaURI, RyaType> entry : predObjs) { - if (first == null) { - first = ryaQueryEngine.query(new RyaStatement(null, entry.getKey(), entry.getValue()), null); - } else if (iter == null) { - iter = join(new ConvertingIteration<RyaStatement, RyaURI, RyaDAOException>(first) { - - @Override - protected RyaURI convert(RyaStatement statement) throws RyaDAOException { - return statement.getSubject(); - } - }, entry); - } else { - iter = join(iter, entry); - } - } - - return iter; - } - - protected CloseableIteration<RyaURI, RyaDAOException> join(final CloseableIteration<RyaURI, RyaDAOException> iteration, - final Map.Entry<RyaURI, RyaType> predObj) { - //TODO: configure batch - //TODO: batch = 1, does not work - final int batch = 100; - return new CloseableIteration<RyaURI, RyaDAOException>() { - - private CloseableIteration<Map.Entry<RyaStatement, BindingSet>, RyaDAOException> query; - - @Override - public void close() throws RyaDAOException { - iteration.close(); - if (query != null) { - query.close(); - } - } - - @Override - public boolean hasNext() throws RyaDAOException { - return !(query == null || !query.hasNext()) || batchNext(); - } - - @Override - public RyaURI next() throws RyaDAOException { - if (query == null || !query.hasNext()) { - if (!batchNext()) return null; - } - if (query != null && query.hasNext()) { - return query.next().getKey().getSubject(); - } else { - return null; - } - } - - private boolean batchNext() throws RyaDAOException { - if (!iteration.hasNext()) { - return false; - } - Collection<Map.Entry<RyaStatement, BindingSet>> batchedResults = new ArrayList<Map.Entry<RyaStatement, BindingSet>>(); - for (int i = 0; i < batch && iteration.hasNext(); i++) { - batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>( - new RyaStatement(iteration.next(), predObj.getKey(), predObj.getValue()), null)); - } - query = ryaQueryEngine.queryWithBindingSet(batchedResults, null); - return query.hasNext(); - } - - @Override - public void remove() throws RyaDAOException { - this.next(); - } - }; - } - - protected CloseableIteration<RyaStatement, RyaDAOException> join( - final CloseableIteration<RyaStatement, RyaDAOException> iteration, final RyaURI pred) { - //TODO: configure batch - //TODO: batch = 1, does not work - final int batch = 100; - return new CloseableIteration<RyaStatement, RyaDAOException>() { - - private CloseableIteration<Map.Entry<RyaStatement, BindingSet>, RyaDAOException> query; - - @Override - public void close() throws RyaDAOException { - iteration.close(); - if (query != null) { - query.close(); - } - } - - @Override - public boolean hasNext() throws RyaDAOException { - return !(query == null || !query.hasNext()) || batchNext(); - } - - @Override - public RyaStatement next() throws RyaDAOException { - if (query == null || !query.hasNext()) { - if (!batchNext()) return null; - } - if (query != null && query.hasNext()) { - return query.next().getKey(); - } else { - return null; - } - } - - private boolean batchNext() throws RyaDAOException { - if (!iteration.hasNext()) { - return false; - } - Collection<Map.Entry<RyaStatement, BindingSet>> batchedResults = new ArrayList<Map.Entry<RyaStatement, BindingSet>>(); - for (int i = 0; i < batch && iteration.hasNext(); i++) { - RyaStatement next = iteration.next(); - batchedResults.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>( - new RyaStatement(next.getSubject(), pred, next.getObject()), null)); - } - query = ryaQueryEngine.queryWithBindingSet(batchedResults, null); - return query.hasNext(); - } - - @Override - public void remove() throws RyaDAOException { - this.next(); - } - }; - } - - public RyaQueryEngine getRyaQueryEngine() { - return ryaQueryEngine; - } - - public void setRyaQueryEngine(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/Join.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/Join.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/Join.java deleted file mode 100644 index 775af53..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/Join.java +++ /dev/null @@ -1,44 +0,0 @@ -package mvm.rya.api.persist.query.join; - -/* - * 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. - */ - - - -import info.aduna.iteration.CloseableIteration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.persist.RyaDAOException; - -import java.util.Map; - -/** - * Date: 7/24/12 - * Time: 4:28 PM - */ -public interface Join<C extends RdfCloudTripleStoreConfiguration> { - - CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) - throws RyaDAOException; - - CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) - throws RyaDAOException; -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/MergeJoin.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/MergeJoin.java b/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/MergeJoin.java deleted file mode 100644 index 1dfcbf1..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/query/join/MergeJoin.java +++ /dev/null @@ -1,244 +0,0 @@ -package mvm.rya.api.persist.query.join; - -/* - * 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. - */ - - - -import com.google.common.base.Preconditions; -import info.aduna.iteration.CloseableIteration; -import info.aduna.iteration.EmptyIteration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.*; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.query.RyaQueryEngine; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.utils.PeekingCloseableIteration; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Date: 7/24/12 - * Time: 8:52 AM - */ -public class MergeJoin<C extends RdfCloudTripleStoreConfiguration> implements Join<C> { - - private RyaContext ryaContext = RyaContext.getInstance(); - private RyaQueryEngine ryaQueryEngine; - - public MergeJoin() { - } - - public MergeJoin(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } - - /** - * Return all statements that have input predicates. Predicates must not be null or ranges - * - * @param preds - * @return - */ - @Override - public CloseableIteration<RyaStatement, RyaDAOException> join(C conf, RyaURI... preds) - throws RyaDAOException { - Preconditions.checkNotNull(preds); - Preconditions.checkArgument(preds.length > 1, "Must join 2 or more"); - //TODO: Reorder predObjs based on statistics - final List<CloseableIteration<RyaStatement, RyaDAOException>> iters = new ArrayList<CloseableIteration<RyaStatement, RyaDAOException>>(); - for (RyaURI predicate : preds) { - Preconditions.checkArgument(predicate != null && !(predicate instanceof RyaRange)); - - CloseableIteration<RyaStatement, RyaDAOException> iter = ryaQueryEngine.query(new RyaStatement(null, predicate, null), conf); - iters.add(iter); - } - Preconditions.checkArgument(iters.size() > 1, "Must join 2 or more"); - - final CloseableIteration<RyaStatement, RyaDAOException> first = iters.remove(0); - - //perform merge operation - - return new CloseableIteration<RyaStatement, RyaDAOException>() { - - private RyaStatement first_stmt; - private RyaType first_obj; - - @Override - public void close() throws RyaDAOException { - for (CloseableIteration<RyaStatement, RyaDAOException> iter : iters) { - iter.close(); - } - } - - @Override - public boolean hasNext() throws RyaDAOException { - return first_stmt != null || check(); - } - - @Override - public RyaStatement next() throws RyaDAOException { - if (first_stmt != null) { - RyaStatement temp = first_stmt; - first_stmt = null; - return temp; - } - if (check()) { - RyaStatement temp = first_stmt; - first_stmt = null; - return temp; - } - return null; - } - - @Override - public void remove() throws RyaDAOException { - this.next(); - } - - protected boolean check() throws RyaDAOException { - if (!first.hasNext()) return false; - first_stmt = first.next(); - first_obj = first_stmt.getObject(); - for (CloseableIteration<RyaStatement, RyaDAOException> iter : iters) { - if (!iter.hasNext()) return false; //no more left to join - RyaType iter_obj = iter.next().getObject(); - while (first_obj.compareTo(iter_obj) < 0) { - if (!first.hasNext()) return false; - first_obj = first.next().getObject(); - } - while (first_obj.compareTo(iter_obj) > 0) { - if (!iter.hasNext()) return false; - iter_obj = iter.next().getObject(); - } - } - return true; - } - }; - } - - /** - * Return all subjects that have the predicate objects associated. Predicate and objects must be not null or ranges - * to ensure sorting - * - * @param predObjs - * @return - * @throws RyaDAOException - */ - @Override - public CloseableIteration<RyaURI, RyaDAOException> join(C conf, Map.Entry<RyaURI, RyaType>... predObjs) - throws RyaDAOException { - Preconditions.checkNotNull(predObjs); - Preconditions.checkArgument(predObjs.length > 1, "Must join 2 or more"); - - //TODO: Reorder predObjs based on statistics - final List<CloseableIteration<RyaStatement, RyaDAOException>> iters = new ArrayList<CloseableIteration<RyaStatement, RyaDAOException>>(); - RyaURI earliest_subject = null; - for (Map.Entry<RyaURI, RyaType> predObj : predObjs) { - RyaURI predicate = predObj.getKey(); - RyaType object = predObj.getValue(); - Preconditions.checkArgument(predicate != null && !(predicate instanceof RyaRange)); - Preconditions.checkArgument(object != null && !(object instanceof RyaRange)); - - PeekingCloseableIteration<RyaStatement, RyaDAOException> iter = null; - if (earliest_subject == null) { - iter = new PeekingCloseableIteration<RyaStatement, RyaDAOException>( - ryaQueryEngine.query(new RyaStatement(null, predicate, object), conf)); - } else { - iter = new PeekingCloseableIteration<RyaStatement, RyaDAOException>( - ryaQueryEngine.query(new RyaStatement(new RyaURIRange(earliest_subject, RyaURIRange.LAST_URI), predicate, object), conf)); - } - if (!iter.hasNext()) { - return new EmptyIteration<RyaURI, RyaDAOException>(); - } - //setting up range to make performant query - earliest_subject = iter.peek().getSubject(); - iters.add(iter); - } - Preconditions.checkArgument(iters.size() > 1, "Must join 2 or more"); - - final CloseableIteration<RyaStatement, RyaDAOException> first = iters.remove(0); - - //perform merge operation - - return new CloseableIteration<RyaURI, RyaDAOException>() { - - private RyaURI first_subj; - - @Override - public void close() throws RyaDAOException { - for (CloseableIteration<RyaStatement, RyaDAOException> iter : iters) { - iter.close(); - } - } - - @Override - public boolean hasNext() throws RyaDAOException { - return first_subj != null || check(); - } - - @Override - public RyaURI next() throws RyaDAOException { - if (first_subj != null) { - RyaURI temp = first_subj; - first_subj = null; - return temp; - } - if (check()) { - RyaURI temp = first_subj; - first_subj = null; - return temp; - } - return null; - } - - @Override - public void remove() throws RyaDAOException { - this.next(); - } - - protected boolean check() throws RyaDAOException { - if (!first.hasNext()) return false; - first_subj = first.next().getSubject(); - for (CloseableIteration<RyaStatement, RyaDAOException> iter : iters) { - if (!iter.hasNext()) return false; //no more left to join - RyaURI iter_subj = iter.next().getSubject(); - while (first_subj.compareTo(iter_subj) < 0) { - if (!first.hasNext()) return false; - first_subj = first.next().getSubject(); - } - while (first_subj.compareTo(iter_subj) > 0) { - if (!iter.hasNext()) return false; - iter_subj = iter.next().getSubject(); - } - } - return true; - } - }; - } - - public RyaQueryEngine getRyaQueryEngine() { - return ryaQueryEngine; - } - - public void setRyaQueryEngine(RyaQueryEngine ryaQueryEngine) { - this.ryaQueryEngine = ryaQueryEngine; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/persist/utils/RyaDAOHelper.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/persist/utils/RyaDAOHelper.java b/common/rya.api/src/main/java/mvm/rya/api/persist/utils/RyaDAOHelper.java deleted file mode 100644 index 81f42b4..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/persist/utils/RyaDAOHelper.java +++ /dev/null @@ -1,176 +0,0 @@ -package mvm.rya.api.persist.utils; - -/* - * 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. - */ - - - -import info.aduna.iteration.CloseableIteration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAO; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.resolver.RdfToRyaConversions; -import mvm.rya.api.resolver.RyaToRdfConversions; -import mvm.rya.api.utils.NullableStatementImpl; -import org.openrdf.model.Resource; -import org.openrdf.model.Statement; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.query.BindingSet; -import org.openrdf.query.QueryEvaluationException; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.NoSuchElementException; - -/** - * Date: 7/20/12 - * Time: 10:36 AM - */ -public class RyaDAOHelper { - - public static CloseableIteration<Statement, QueryEvaluationException> query(RyaDAO ryaDAO, Resource subject, URI predicate, Value object, RdfCloudTripleStoreConfiguration conf, Resource... contexts) throws QueryEvaluationException { - return query(ryaDAO, new NullableStatementImpl(subject, predicate, object, contexts), conf); - } - - public static CloseableIteration<Statement, QueryEvaluationException> query(RyaDAO ryaDAO, Statement stmt, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException { - final CloseableIteration<RyaStatement, RyaDAOException> query; - try { - query = ryaDAO.getQueryEngine().query(RdfToRyaConversions.convertStatement(stmt), - conf); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - //TODO: only support one context for now - return new CloseableIteration<Statement, QueryEvaluationException>() { //TODO: Create a new class struct for this - - private boolean isClosed = false; - @Override - public void close() throws QueryEvaluationException { - try { - isClosed = true; - query.close(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public boolean hasNext() throws QueryEvaluationException { - try { - return query.hasNext(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public Statement next() throws QueryEvaluationException { - if (!hasNext() || isClosed) { - throw new NoSuchElementException(); - } - - try { - RyaStatement next = query.next(); - if (next == null) { - return null; - } - return RyaToRdfConversions.convertStatement(next); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public void remove() throws QueryEvaluationException { - try { - query.remove(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - }; - } - - public static CloseableIteration<? extends Map.Entry<Statement, BindingSet>, QueryEvaluationException> query(RyaDAO ryaDAO, Collection<Map.Entry<Statement, BindingSet>> statements, RdfCloudTripleStoreConfiguration conf) throws QueryEvaluationException { - Collection<Map.Entry<RyaStatement, BindingSet>> ryaStatements = new ArrayList<Map.Entry<RyaStatement, BindingSet>>(statements.size()); - for (Map.Entry<Statement, BindingSet> entry : statements) { - ryaStatements.add(new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet> - (RdfToRyaConversions.convertStatement(entry.getKey()), entry.getValue())); - } - final CloseableIteration<? extends Map.Entry<RyaStatement, BindingSet>, RyaDAOException> query; - try { - query = ryaDAO.getQueryEngine().queryWithBindingSet(ryaStatements, conf); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - return new CloseableIteration<Map.Entry<Statement, BindingSet>, QueryEvaluationException>() { //TODO: Create a new class struct for this - private boolean isClosed = false; - - @Override - public void close() throws QueryEvaluationException { - isClosed = true; - try { - query.close(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public boolean hasNext() throws QueryEvaluationException { - try { - return query.hasNext(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public Map.Entry<Statement, BindingSet> next() throws QueryEvaluationException { - if (!hasNext() || isClosed) { - throw new NoSuchElementException(); - } - try { - - Map.Entry<RyaStatement, BindingSet> next = query.next(); - if (next == null) { - return null; - } - return new RdfCloudTripleStoreUtils.CustomEntry<Statement, BindingSet>(RyaToRdfConversions.convertStatement(next.getKey()), next.getValue()); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - - @Override - public void remove() throws QueryEvaluationException { - try { - query.remove(); - } catch (RyaDAOException e) { - throw new QueryEvaluationException(e); - } - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/AbstractTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/AbstractTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/AbstractTriplePatternStrategy.java deleted file mode 100644 index 5171feb..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/AbstractTriplePatternStrategy.java +++ /dev/null @@ -1,93 +0,0 @@ -package mvm.rya.api.query.strategy; - -/* - * 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. - */ - - - -import com.google.common.base.Preconditions; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.triple.TripleRowRegex; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM; - -/** - * Date: 7/14/12 - * Time: 8:06 AM - */ -public abstract class AbstractTriplePatternStrategy implements TriplePatternStrategy { - public static final String ALL_REGEX = "([\\s\\S]*)"; - - public abstract RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout(); - - @Override - public TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo) { - RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = getLayout(); - Preconditions.checkNotNull(table_layout); - if (subject == null && predicate == null && object == null && context == null && objectTypeInfo == null) { - return null; //no regex - } - StringBuilder sb = new StringBuilder(); - String first = subject; - String second = predicate; - String third = object; - if (table_layout == RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO) { - first = predicate; - second = object; - third = subject; - } else if (table_layout == RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP) { - first = object; - second = subject; - third = predicate; - } - - if (first != null) { - sb.append(first); - } else { - sb.append(ALL_REGEX); - } - sb.append(DELIM); - - if (second != null) { - sb.append(second); - } else { - sb.append(ALL_REGEX); - } - sb.append(DELIM); - - if (third != null) { - sb.append(third); - if (objectTypeInfo == null) { - sb.append(TYPE_DELIM); - sb.append(ALL_REGEX); - }else { - sb.append(new String(objectTypeInfo)); - } - }else { - sb.append(ALL_REGEX); - if (objectTypeInfo != null) { - sb.append(new String(objectTypeInfo)); - } - } - - return new TripleRowRegex(sb.toString(), (context != null) ? (context + ALL_REGEX) : null, null); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java deleted file mode 100644 index 6ebc722..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/ByteRange.java +++ /dev/null @@ -1,45 +0,0 @@ -package mvm.rya.api.query.strategy; - -/* - * 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. - */ - - - -/** - * Date: 1/10/13 - * Time: 12:47 PM - */ -public class ByteRange { - - private byte[] start; - private byte[] end; - - public ByteRange(byte[] start, byte[] end) { - this.start = start; - this.end = end; - } - - public byte[] getStart() { - return start; - } - - public byte[] getEnd() { - return end; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java deleted file mode 100644 index 7b7eb39..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/TriplePatternStrategy.java +++ /dev/null @@ -1,49 +0,0 @@ -package mvm.rya.api.query.strategy; - -/* - * 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. - */ - - - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.resolver.triple.TripleRowRegex; - -import java.io.IOException; -import java.util.Map; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; - -/** - * Date: 7/14/12 - * Time: 7:21 AM - */ -public interface TriplePatternStrategy { - - public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context, - RdfCloudTripleStoreConfiguration conf) throws IOException; - - public TABLE_LAYOUT getLayout(); - - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context); - - public TripleRowRegex buildRegex(String subject, String predicate, String object, String context, byte[] objectTypeInfo); - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java deleted file mode 100644 index 04d81ce..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedPoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,135 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.TYPE_DELIM_BYTES; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import com.google.common.primitives.Bytes; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class HashedPoWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - @Override - public RdfCloudTripleStoreConstants.TABLE_LAYOUT getLayout() { - return RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - } - - @Override - public Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //po(ng) - //po_r(s)(ng) - //p(ng) - //p_r(o)(ng) - //r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - MessageDigest md = MessageDigest.getInstance("MD5"); - - - RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO; - byte[] start, stop; - if (object != null) { - if (object instanceof RyaRange) { - //p_r(o) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = md.digest(predBytes); - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(predHash, DELIM_BYTES, predBytes,DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - if (subject != null && subject instanceof RyaRange) { - //po_r(s) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - byte[] subjStartBytes = ru.getStart().getData().getBytes(); - byte[] subjStopBytes = ru.getStop().getData().getBytes(); - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = md.digest(predBytes); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStartBytes); - stop = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStopBytes, TYPE_DELIM_BYTES, LAST_BYTES); - } else { - //po - //TODO: There must be a better way than creating multiple byte[] - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = md.digest(predBytes); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES, objBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } - } else { - //p - byte[] predBytes = predicate.getData().getBytes(); - byte[] predHash = md.digest(predBytes); - start = Bytes.concat(predHash, DELIM_BYTES, predBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, - ByteRange>(table_layout, new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } catch (NoSuchAlgorithmException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //po(ng) - //p_r(o)(ng) - //po_r(s)(ng) - //p(ng) - //r(p)(ng) - if ((predicate == null) || (predicate instanceof RyaRange)) return false; - if (subject != null && !(subject instanceof RyaRange)) return false; - return subject == null || object != null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java deleted file mode 100644 index b7204a9..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/HashedSpoWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,138 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import com.google.common.primitives.Bytes; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.domain.RyaURIRange; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import static mvm.rya.api.RdfCloudTripleStoreConstants.*; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class HashedSpoWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - - @Override - public TABLE_LAYOUT getLayout() { - return TABLE_LAYOUT.SPO; - } - - @Override - public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //spo(ng) - //sp(ng) - //s(ng) - //sp_r(o)(ng) - //s_r(p)(ng) - if (!handles(subject, predicate, object, context)) return null; - MessageDigest md = MessageDigest.getInstance("MD5"); - - RyaContext ryaContext = RyaContext.getInstance(); - - TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO; - byte[] start; - byte[] stop; - if (predicate != null) { - if (object != null) { - if (object instanceof RyaRange) { - //sp_r(o) - //range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0]; - byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0]; - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = md.digest(subjBytes); - byte[] predBytes = predicate.getData().getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes); - stop = Bytes.concat(hashSubj, DELIM_BYTES,subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - //spo - //range = spo->spo (remove last byte to remove type info) - //TODO: There must be a better way than creating multiple byte[] - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = md.digest(subjBytes); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else if (predicate instanceof RyaRange) { - //s_r(p) - //range = s_r(p.s)->s_r(p.e) - RyaRange rv = (RyaRange) predicate; - rv = ryaContext.transformRange(rv); - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = md.digest(subjBytes); - byte[] predStartBytes = rv.getStart().getData().getBytes(); - byte[] predStopBytes = rv.getStop().getData().getBytes(); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predStartBytes); - stop = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES); - } else { - //sp - //range = sp - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = md.digest(subjBytes); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES, predicate.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else { - //s - //range = s - byte[] subjBytes = subject.getData().getBytes(); - byte[] hashSubj = md.digest(subjBytes); - start = Bytes.concat(hashSubj, DELIM_BYTES, subjBytes, DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, - new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } catch (NoSuchAlgorithmException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //if subject is not null and not a range (if predicate is null then object must be null) - return (subject != null && !(subject instanceof RyaURIRange)) && !((predicate == null || predicate instanceof RyaURIRange) && (object != null)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java b/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java deleted file mode 100644 index 24f5852..0000000 --- a/common/rya.api/src/main/java/mvm/rya/api/query/strategy/wholerow/OspWholeRowTriplePatternStrategy.java +++ /dev/null @@ -1,113 +0,0 @@ -package mvm.rya.api.query.strategy.wholerow; - -/* - * 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. - */ - - - -import static mvm.rya.api.RdfCloudTripleStoreConstants.DELIM_BYTES; -import static mvm.rya.api.RdfCloudTripleStoreConstants.LAST_BYTES; - -import java.io.IOException; -import java.util.Map; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaRange; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.query.strategy.AbstractTriplePatternStrategy; -import mvm.rya.api.query.strategy.ByteRange; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTypeResolverException; - -import com.google.common.primitives.Bytes; - -/** - * Date: 7/14/12 - * Time: 7:35 AM - */ -public class OspWholeRowTriplePatternStrategy extends AbstractTriplePatternStrategy { - - @Override - public TABLE_LAYOUT getLayout() { - return TABLE_LAYOUT.OSP; - } - - @Override - public Map.Entry<TABLE_LAYOUT, - ByteRange> defineRange(RyaURI subject, RyaURI predicate, RyaType object, - RyaURI context, RdfCloudTripleStoreConfiguration conf) throws IOException { - try { - //os(ng) - //o_r(s)(ng) - //o(ng) - //r(o) - if (!handles(subject, predicate, object, context)) return null; - - RyaContext ryaContext = RyaContext.getInstance(); - - TABLE_LAYOUT table_layout = TABLE_LAYOUT.OSP; - byte[] start, stop; - if (subject != null) { - if (subject instanceof RyaRange) { - //o_r(s) - RyaRange ru = (RyaRange) subject; - ru = ryaContext.transformRange(ru); - byte[] subjStartBytes = ru.getStart().getData().getBytes(); - byte[] subjEndBytes = ru.getStop().getData().getBytes(); - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(objBytes, DELIM_BYTES, subjStartBytes); - stop = Bytes.concat(objBytes, DELIM_BYTES, subjEndBytes, DELIM_BYTES, LAST_BYTES); - } else { - //os - byte[] objBytes = ryaContext.serializeType(object)[0]; - start = Bytes.concat(objBytes, DELIM_BYTES, subject.getData().getBytes(), DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } else { - if (object instanceof RyaRange) { - //r(o) - RyaRange rv = (RyaRange) object; - rv = ryaContext.transformRange(rv); - start = ryaContext.serializeType(rv.getStart())[0]; - stop = Bytes.concat(ryaContext.serializeType(rv.getStop())[0], DELIM_BYTES, LAST_BYTES); - } else { - //o - start = Bytes.concat(ryaContext.serializeType(object)[0], DELIM_BYTES); - stop = Bytes.concat(start, LAST_BYTES); - } - } - return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, - ByteRange>(table_layout, new ByteRange(start, stop)); - } catch (RyaTypeResolverException e) { - throw new IOException(e); - } - } - - @Override - public boolean handles(RyaURI subject, RyaURI predicate, RyaType object, RyaURI context) { - //os(ng) - //o_r(s)(ng) - //o(ng) - //r(o) - return object != null && (!(object instanceof RyaRange) || predicate == null && subject == null); - } -}
