This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch ignite-14972
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-14972 by this push:
new ed71fb9f0 readRows implemented
ed71fb9f0 is described below
commit ed71fb9f0e30aabb3c0cade5c80d8ad31f01d514
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Mon May 30 21:13:11 2022 +0300
readRows implemented
---
.../handler/requests/sql/ClientSqlCommon.java | 4 +-
.../internal/client/sql/ClientAsyncResultSet.java | 40 +++++++++---
.../internal/client/sql/ClientColumnMetadata.java | 62 +++++++++++++++++++
.../client/sql/ClientResultSetMetadata.java | 72 ++++++++++++++++++++++
4 files changed, 166 insertions(+), 12 deletions(-)
diff --git
a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/sql/ClientSqlCommon.java
b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/sql/ClientSqlCommon.java
index a480d92b3..697c7f200 100644
---
a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/sql/ClientSqlCommon.java
+++
b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/sql/ClientSqlCommon.java
@@ -30,11 +30,11 @@ class ClientSqlCommon {
static void packCurrentPage(ClientMessagePacker out, AsyncResultSet
asyncResultSet) {
List<ColumnMetadata> cols = asyncResultSet.metadata().columns();
- out.packInt(asyncResultSet.currentPageSize());
+ out.packArrayHeader(asyncResultSet.currentPageSize());
for (SqlRow row : asyncResultSet.currentPage()) {
for (int i = 0; i < cols.size(); i++) {
- // TODO: IGNITE-16962 pack only the value according to the
known type.
+ // TODO: IGNITE-17052 pack only the value according to the
known type.
out.packObjectWithType(row.value(i));
}
}
diff --git
a/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java
index d3874a795..fd6233ec1 100644
---
a/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java
+++
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientAsyncResultSet.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.client.sql;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletionStage;
import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
@@ -37,9 +38,6 @@ class ClientAsyncResultSet implements AsyncResultSet {
/** */
private final boolean hasRowSet;
- /** */
- private final boolean hasMorePages;
-
/** */
private final boolean wasApplied;
@@ -47,7 +45,13 @@ class ClientAsyncResultSet implements AsyncResultSet {
private final long affectedRows;
/** */
- private final List<SqlRow> rows;
+ private final ResultSetMetadata metadata;
+
+ /** */
+ private List<SqlRow> rows;
+
+ /** */
+ private final boolean hasMorePages;
/**
* Constructor.
@@ -55,20 +59,16 @@ class ClientAsyncResultSet implements AsyncResultSet {
* @param in Unpacker.
*/
public ClientAsyncResultSet(ClientMessageUnpacker in) {
-
resourceId = in.tryUnpackNil() ? null : in.unpackLong();
hasRowSet = in.unpackBoolean();
hasMorePages = in.unpackBoolean();
wasApplied = in.unpackBoolean();
affectedRows = in.unpackLong();
- in.unpackArrayHeader(); // TODO: Metadata IGNITE-17052.
+ metadata = new ClientResultSetMetadata(in);
if (hasRowSet) {
- // TODO: Unpack rows.
- rows = new ArrayList<>();
- } else {
- rows = null;
+ readRows(in);
}
}
@@ -141,4 +141,24 @@ class ClientAsyncResultSet implements AsyncResultSet {
throw new NoRowSetExpectedException("Query has no result set");
}
}
+
+ private void readRows(ClientMessageUnpacker in) {
+ int size = in.unpackArrayHeader();
+ int rowSize = metadata.columns().size();
+
+ var res = new ArrayList<SqlRow>(size);
+
+ for (int i = 0; i < size; i++) {
+ var row = new ArrayList<>(rowSize);
+
+ for (int j = 0; j < rowSize; j++) {
+ // TODO: IGNITE-17052 Unpack according to metadata type.
+ row.add(in.unpackObjectWithType());
+ }
+
+ res.add(new ClientSqlRow(row));
+ }
+
+ rows = Collections.unmodifiableList(res);
+ }
}
diff --git
a/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientColumnMetadata.java
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientColumnMetadata.java
new file mode 100644
index 000000000..20800e170
--- /dev/null
+++
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientColumnMetadata.java
@@ -0,0 +1,62 @@
+package org.apache.ignite.internal.client.sql;
+
+import org.apache.ignite.client.IgniteClientException;
+import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.sql.ColumnMetadata;
+
+/**
+ * Client column metadata.
+ */
+public class ClientColumnMetadata implements ColumnMetadata {
+ /** */
+ private final String name;
+
+ /** */
+ private final Class<?> valueClass;
+
+ /** */
+ private final Object type;
+
+ /** */
+ private final boolean nullable;
+
+ /**
+ * Constructor.
+ *
+ * @param unpacker Unpacker.
+ */
+ public ClientColumnMetadata(ClientMessageUnpacker unpacker) {
+ try {
+ name = unpacker.unpackString();
+ valueClass = Class.forName(unpacker.unpackString());
+ type = unpacker.unpackObjectWithType();
+ nullable = unpacker.unpackBoolean();
+ } catch (ClassNotFoundException e) {
+ throw new IgniteClientException(e.getMessage(), e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String name() {
+ return name;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Class<?> valueClass() {
+ return valueClass;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Object type() {
+ return type;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean nullable() {
+ return nullable;
+ }
+}
diff --git
a/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientResultSetMetadata.java
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientResultSetMetadata.java
new file mode 100644
index 000000000..a3269212d
--- /dev/null
+++
b/modules/client/src/main/java/org/apache/ignite/internal/client/sql/ClientResultSetMetadata.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.client.sql;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.sql.ColumnMetadata;
+import org.apache.ignite.sql.ResultSetMetadata;
+
+/**
+ * Result set metadata.
+ */
+class ClientResultSetMetadata implements ResultSetMetadata {
+ /** */
+ private final List<ColumnMetadata> columns;
+
+ /** */
+ private final Map<String, Integer> columnIndices;
+
+ /**
+ * Constructor.
+ *
+ * @param unpacker Unpacker.
+ */
+ public ClientResultSetMetadata(ClientMessageUnpacker unpacker) {
+ var size = unpacker.unpackArrayHeader();
+
+ var columns = new ArrayList<ColumnMetadata>(size);
+ columnIndices = new HashMap<>(size);
+
+ for (int i = 0; i < size; i++) {
+ ClientColumnMetadata column = new ClientColumnMetadata(unpacker);
+ columns.add(column);
+ columnIndices.put(column.name(), i);
+ }
+
+ this.columns = Collections.unmodifiableList(columns);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public List<ColumnMetadata> columns() {
+ return columns;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int indexOf(String columnName) {
+ Integer index = columnIndices.get(columnName);
+
+ return index == null ? -1 : index;
+ }
+}