Repository: incubator-ignite Updated Branches: refs/heads/ignite-gg9499 [created] 67df1ce35
ignite-gg9499 - Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/4da1d1a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/4da1d1a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/4da1d1a4 Branch: refs/heads/ignite-gg9499 Commit: 4da1d1a496c3eb8e0e73a397fcd02322f3508416 Parents: c67dcde Author: S.Vladykin <svlady...@gridgain.com> Authored: Fri Dec 12 16:34:17 2014 +0300 Committer: S.Vladykin <svlady...@gridgain.com> Committed: Fri Dec 12 16:34:17 2014 +0300 ---------------------------------------------------------------------- .../query/h2/twostep/GridMergeIndex.java | 162 +++++++++++++++++++ .../query/h2/twostep/GridMergeTable.java | 145 +++++++++++++++++ .../query/h2/twostep/GridNextPageRequest.java | 54 +++++++ .../query/h2/twostep/GridNextPageResponse.java | 47 ++++++ .../query/h2/twostep/GridQueryAck.java | 42 +++++ .../query/h2/twostep/GridQueryRequest.java | 50 ++++++ 6 files changed, 500 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeIndex.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeIndex.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeIndex.java new file mode 100644 index 0000000..163256b --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeIndex.java @@ -0,0 +1,162 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.gridgain.grid.*; +import org.h2.engine.*; +import org.h2.index.*; +import org.h2.message.*; +import org.h2.result.*; +import org.h2.table.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * Merge index. + */ +public class GridMergeIndex extends BaseIndex { + /** */ + private static final int MAX_CAPACITY = 100_000; + + /** */ + private static final Collection<Row> END = new ArrayList<>(0); + + /** */ + private Collection<Collection<Row>> fetchedRows = new LinkedBlockingQueue<>(); + + /** */ + private BlockingQueue<Collection<Row>> cursorRows = new LinkedBlockingQueue<>(); + + /** */ + private int fetchedCnt; + + /** */ + private final AtomicInteger cnt = new AtomicInteger(0); + + /** {@inheritDoc} */ + @Override public long getRowCount(Session session) { + return cnt.get(); + } + + /** {@inheritDoc} */ + @Override public long getRowCountApproximation() { + return getRowCount(null); + } + + /** + * @param cnt Count. + */ + public void addCount(int cnt) { + this.cnt.addAndGet(cnt); + } + + /** + * @param rows0 Rows. + */ + public void addRows(Collection<Row> rows0) { + assert !rows0.isEmpty(); + + + } + + /** {@inheritDoc} */ + @Override public void checkRename() { + throw DbException.getUnsupportedException("rename"); + } + + /** {@inheritDoc} */ + @Override public void close(Session session) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void add(Session session, Row row) { + throw DbException.getUnsupportedException("add"); + } + + /** {@inheritDoc} */ + @Override public void remove(Session session, Row row) { + throw DbException.getUnsupportedException("remove row"); + } + + /** {@inheritDoc} */ + @Override public Cursor find(Session session, SearchRow first, SearchRow last) { + if (fetchedRows == null) + throw new GridRuntimeException("Rows were dropped out of result set."); + + return new Cursor0(); + } + + /** {@inheritDoc} */ + @Override public double getCost(Session session, int[] masks, TableFilter filter, SortOrder sortOrder) { + return getRowCountApproximation() + Constants.COST_ROW_OFFSET; + } + + /** {@inheritDoc} */ + @Override public void remove(Session session) { + throw DbException.getUnsupportedException("remove index"); + } + + /** {@inheritDoc} */ + @Override public void truncate(Session session) { + throw DbException.getUnsupportedException("truncate"); + } + + /** {@inheritDoc} */ + @Override public boolean canGetFirstOrLast() { + return false; + } + + /** {@inheritDoc} */ + @Override public Cursor findFirstOrLast(Session session, boolean first) { + throw DbException.getUnsupportedException("findFirstOrLast"); + } + + /** {@inheritDoc} */ + @Override public boolean needRebuild() { + return false; + } + + /** {@inheritDoc} */ + @Override public long getDiskSpaceUsed() { + return 0; + } + + private class Cursor0 implements Cursor { + /** */ + private Row cur; + + /** */ + private Iterator<Row> curIter; + + /** {@inheritDoc} */ + @Override public Row get() { + return cur; + } + + /** {@inheritDoc} */ + @Override public SearchRow getSearchRow() { + return get(); + } + + /** {@inheritDoc} */ + @Override public boolean next() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean previous() { + throw DbException.getUnsupportedException("previous"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeTable.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeTable.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeTable.java new file mode 100644 index 0000000..3f059fa --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridMergeTable.java @@ -0,0 +1,145 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.h2.command.ddl.*; +import org.h2.engine.*; +import org.h2.index.*; +import org.h2.message.*; +import org.h2.result.*; +import org.h2.table.*; + +import java.util.*; + +/** + * Merge table for distributed queries. + */ +public class GridMergeTable extends TableBase { + /** */ + private final ArrayList<Index> idxs = new ArrayList<>(1); + + /** */ + private final GridMergeIndex idx = new GridMergeIndex(); + + /** + * @param data Data. + */ + public GridMergeTable(CreateTableData data) { + super(data); + + idxs.add(idx); + } + + /** {@inheritDoc} */ + @Override public void lock(Session session, boolean exclusive, boolean force) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void close(Session ses) { + idx.close(ses); + } + + /** {@inheritDoc} */ + @Override public void unlock(Session s) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public Index addIndex(Session session, String indexName, int indexId, IndexColumn[] cols, + IndexType indexType, boolean create, String indexComment) { + throw DbException.getUnsupportedException("addIndex"); + } + + /** {@inheritDoc} */ + @Override public void removeRow(Session session, Row row) { + throw DbException.getUnsupportedException("removeRow"); + } + + /** {@inheritDoc} */ + @Override public void truncate(Session session) { + throw DbException.getUnsupportedException("truncate"); + } + + /** {@inheritDoc} */ + @Override public void addRow(Session session, Row row) { + throw DbException.getUnsupportedException("addRow"); + } + + /** {@inheritDoc} */ + @Override public void checkSupportAlter() { + throw DbException.getUnsupportedException("alter"); + } + + /** {@inheritDoc} */ + @Override public String getTableType() { + return EXTERNAL_TABLE_ENGINE; + } + + /** {@inheritDoc} */ + @Override public GridMergeIndex getScanIndex(Session session) { + return idx; + } + + /** {@inheritDoc} */ + @Override public Index getUniqueIndex() { + return null; // We don't have a PK. + } + + /** {@inheritDoc} */ + @Override public ArrayList<Index> getIndexes() { + return idxs; + } + + /** {@inheritDoc} */ + @Override public boolean isLockedExclusively() { + return false; + } + + /** {@inheritDoc} */ + @Override public long getMaxDataModificationId() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean isDeterministic() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean canGetRowCount() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean canDrop() { + return true; + } + + /** {@inheritDoc} */ + @Override public long getRowCount(Session ses) { + return idx.getRowCount(ses); + } + + /** {@inheritDoc} */ + @Override public long getRowCountApproximation() { + return idx.getRowCountApproximation(); + } + + /** {@inheritDoc} */ + @Override public long getDiskSpaceUsed() { + return 0; + } + + /** {@inheritDoc} */ + @Override public void checkRename() { + throw DbException.getUnsupportedException("rename"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageRequest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageRequest.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageRequest.java new file mode 100644 index 0000000..d550b3b --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageRequest.java @@ -0,0 +1,54 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.gridgain.grid.util.direct.*; + +import java.nio.*; + +/** + * Request to fetch next page. + */ +public class GridNextPageRequest extends GridTcpCommunicationMessageAdapter { + /** */ + private long reqId; + + /** */ + private long qryId; + + /** */ + private int qry; + + /** */ + private int offset; + + /** */ + private int pageSize; + + @Override public boolean writeTo(ByteBuffer buf) { + return false; + } + + @Override public boolean readFrom(ByteBuffer buf) { + return false; + } + + @Override public byte directType() { + return 0; + } + + @Override public GridTcpCommunicationMessageAdapter clone() { + return null; + } + + @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageResponse.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageResponse.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageResponse.java new file mode 100644 index 0000000..d77215c --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridNextPageResponse.java @@ -0,0 +1,47 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.gridgain.grid.util.direct.*; +import org.h2.value.*; + +import java.nio.*; +import java.util.*; + +/** + * TODO write doc + */ +public class GridNextPageResponse extends GridTcpCommunicationMessageAdapter { + /** */ + private long reqId; + + /** */ + private Collection<Value[]> rows; + + @Override public boolean writeTo(ByteBuffer buf) { + return false; + } + + @Override public boolean readFrom(ByteBuffer buf) { + return false; + } + + @Override public byte directType() { + return 0; + } + + @Override public GridTcpCommunicationMessageAdapter clone() { + return null; + } + + @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryAck.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryAck.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryAck.java new file mode 100644 index 0000000..10e30ee --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryAck.java @@ -0,0 +1,42 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.gridgain.grid.util.direct.*; + +import java.nio.*; + +/** + * TODO write doc + */ +public class GridQueryAck extends GridTcpCommunicationMessageAdapter { + /** */ + private long reqId; + + @Override public boolean writeTo(ByteBuffer buf) { + return false; + } + + @Override public boolean readFrom(ByteBuffer buf) { + return false; + } + + @Override public byte directType() { + return 0; + } + + @Override public GridTcpCommunicationMessageAdapter clone() { + return null; + } + + @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4da1d1a4/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryRequest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryRequest.java b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryRequest.java new file mode 100644 index 0000000..7a664fd --- /dev/null +++ b/modules/indexing/src/main/java/org/gridgain/grid/kernal/processors/query/h2/twostep/GridQueryRequest.java @@ -0,0 +1,50 @@ +/* @java.file.header */ + +/* _________ _____ __________________ _____ + * __ ____/___________(_)______ /__ ____/______ ____(_)_______ + * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \ + * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / / + * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/ + */ + +package org.gridgain.grid.kernal.processors.query.h2.twostep; + +import org.gridgain.grid.util.direct.*; + +import java.nio.*; +import java.util.*; + +/** + * TODO write doc + */ +public class GridQueryRequest extends GridTcpCommunicationMessageAdapter { + /** */ + private long reqId; + + /** */ + private List<String> sqlQrys; + + /** */ + private List<Collection<Object>> params; + + + @Override public boolean writeTo(ByteBuffer buf) { + return false; + } + + @Override public boolean readFrom(ByteBuffer buf) { + return false; + } + + @Override public byte directType() { + return 0; + } + + @Override public GridTcpCommunicationMessageAdapter clone() { + return null; + } + + @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { + + } +}