You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/27 11:45:37 UTC
[49/50] [abbrv] incubator-ignite git commit: #ignite-961: add
metadata for sql fields query.
#ignite-961: add metadata for sql fields query.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/a0f4af95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a0f4af95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a0f4af95
Branch: refs/heads/ignite-961
Commit: a0f4af95eedb3cc2a6c934d10b2639c2cf8206e3
Parents: 206c789
Author: ivasilinets <iv...@gridgain.com>
Authored: Mon Jul 27 12:39:09 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Mon Jul 27 12:39:09 2015 +0300
----------------------------------------------------------------------
.../JettyRestProcessorAbstractSelfTest.java | 33 ++++-
.../processors/rest/GridRestProcessor.java | 8 ++
.../query/CacheQueryFieldsMetaResult.java | 130 ++++++++++++++++++-
.../rest/handlers/query/CacheQueryResult.java | 19 +++
.../handlers/query/QueryCommandHandler.java | 21 +++
.../http/jetty/GridJettyRestHandler.java | 57 --------
6 files changed, 208 insertions(+), 60 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index 5a54cd1..c6363be 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -124,7 +124,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
* @return Request result.
* @throws Exception If failed.
*/
- private String makePostRequest(Map<String, String> params, String postParams) throws Exception {
+ protected String makePostRequest(Map<String, String> params, String postParams) throws Exception {
String addr = "http://" + LOC_HOST + ":" + restPort() + "/ignite?";
for (Map.Entry<String, String> e : params.entrySet())
@@ -1397,6 +1397,37 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
/**
* @throws Exception If failed.
*/
+ public void testSqlFieldsMetadataQuery() throws Exception {
+ String qry = "select firstName, lastName from Person";
+
+ Map<String, String> params = new HashMap<>();
+ params.put("cmd", GridRestCommand.EXECUTE_SQL_FIELDS_QUERY.key());
+ params.put("psz", "10");
+ params.put("cacheName", "person");
+ params.put("qry", URLEncoder.encode(qry));
+
+ String ret = content(params);
+
+ assertNotNull(ret);
+ assertTrue(!ret.isEmpty());
+
+ JSONObject json = JSONObject.fromObject(ret);
+
+ List items = (List)((Map)json.get("response")).get("items");
+
+ List meta = (List)((Map)json.get("response")).get("fieldsMetadata");
+
+ assertEquals(4, items.size());
+
+ assertEquals(2, meta.size());
+
+
+ assertFalse(queryCursorFound());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
public void testQueryClose() throws Exception {
String qry = "salary > ? and salary <= ?";
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index 4b57962..f8ccf8b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -580,6 +580,14 @@ public class GridRestProcessor extends GridProcessorAdapter {
break;
+ case RUN_SCRIPT:
+ case AFFINITY_RUN_SCRIPT:
+ case EXECUTE_MAP_REDUCE_SCRIPT:
+ perm = SecurityPermission.TASK_EXECUTE;
+ name = "";
+
+ break;
+
case GET_OR_CREATE_CACHE:
case DESTROY_CACHE:
perm = SecurityPermission.ADMIN_CACHE;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryFieldsMetaResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryFieldsMetaResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryFieldsMetaResult.java
index 040c44e..8c4ddb0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryFieldsMetaResult.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryFieldsMetaResult.java
@@ -1,7 +1,133 @@
+/*
+ * 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.processors.rest.handlers.query;
+import org.apache.ignite.internal.processors.query.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+
/**
- * Created by GridGain on 27.07.2015.
+ * Cache query fields metadata.
*/
-public class CacheQueryFieldsMetaResult {
+public class CacheQueryFieldsMetaResult implements Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Schema name. */
+ private String schemaName;
+
+ /** Type name. */
+ private String typeName;
+
+ /** Name. */
+ private String fieldName;
+
+ /** Type. */
+ private String fieldTypeName;
+
+ /**
+ * Empty constructor for Externalizable.
+ */
+ public CacheQueryFieldsMetaResult() {
+ // No-op.
+ }
+
+ /**
+ * @param meta Metadata
+ */
+ public CacheQueryFieldsMetaResult(GridQueryFieldMetadata meta) {
+ schemaName = meta.schemaName();
+ typeName = meta.typeName();
+ fieldName = meta.fieldName();
+ fieldTypeName = meta.fieldTypeName();
+ }
+
+ /**
+ * @return Schema name.
+ */
+ public String getSchemaName() {
+ return schemaName;
+ }
+
+ /**
+ * @param schemaName Schema name.
+ */
+ public void setSchemaName(String schemaName) {
+ this.schemaName = schemaName;
+ }
+
+ /**
+ * @return Type name.
+ */
+ public String getTypeName() {
+ return typeName;
+ }
+
+ /**
+ * @param typeName Type name.
+ */
+ public void setTypeName(String typeName) {
+ this.typeName = typeName;
+ }
+
+ /**
+ * @return Field name.
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * @param fieldName Field name.
+ */
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+
+ /**
+ * @return Field type name.
+ */
+ public String getFieldTypeName() {
+ return fieldTypeName;
+ }
+
+ /**
+ * @param fieldName Field name.
+ */
+ public void setFieldTypeName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ U.writeString(out, schemaName);
+ U.writeString(out, typeName);
+ U.writeString(out, fieldName);
+ U.writeString(out, fieldTypeName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ schemaName = U.readString(in);
+ typeName = U.readString(in);
+ fieldName = U.readString(in);
+ fieldTypeName = U.readString(in);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
index 3e49576..544a094 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
@@ -35,6 +35,9 @@ public class CacheQueryResult implements Externalizable {
/** Result items. */
private Collection<?> items;
+ /** Fields metadata. */
+ private Collection<?> fieldsMeta;
+
/** Last flag. */
private boolean last;
@@ -67,6 +70,20 @@ public class CacheQueryResult implements Externalizable {
}
/**
+ * @param fieldsMeta Fields metadata.
+ */
+ public void setFieldsMetadata(Collection<?> fieldsMeta) {
+ this.fieldsMeta = fieldsMeta;
+ }
+
+ /**
+ * @return Fields metadata.
+ */
+ public Collection<?> getFieldsMetadata() {
+ return fieldsMeta;
+ }
+
+ /**
* @return Last flag.
*/
public boolean getLast() {
@@ -90,6 +107,7 @@ public class CacheQueryResult implements Externalizable {
out.writeBoolean(last);
out.writeLong(qryId);
U.writeCollection(out, items);
+ U.writeCollection(out, fieldsMeta);
}
/** {@inheritDoc} */
@@ -97,5 +115,6 @@ public class CacheQueryResult implements Externalizable {
last = in.readBoolean();
qryId = in.readLong();
items = U.readCollection(in);
+ fieldsMeta = U.readCollection(in);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 9457c3a..35fbcef 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -20,6 +20,8 @@ package org.apache.ignite.internal.processors.rest.handlers.query;
import org.apache.ignite.*;
import org.apache.ignite.cache.query.*;
import org.apache.ignite.internal.*;
+import org.apache.ignite.internal.processors.cache.*;
+import org.apache.ignite.internal.processors.query.*;
import org.apache.ignite.internal.processors.rest.*;
import org.apache.ignite.internal.processors.rest.handlers.*;
import org.apache.ignite.internal.processors.rest.request.*;
@@ -146,6 +148,10 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
CacheQueryResult res = createQueryResult(qryCurs, cur, req, qryId, ctx);
+ List<GridQueryFieldMetadata> fieldsMeta = ((QueryCursorImpl) qryCur).fieldsMeta();
+
+ res.setFieldsMetadata(convertMetadata(fieldsMeta));
+
return new GridRestResponse(res);
}
catch (Exception e) {
@@ -154,6 +160,21 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
}
}
+
+ /**
+ * @param meta Internal query field metadata.
+ * @return Rest query field metadata.
+ */
+ private Collection<CacheQueryFieldsMetaResult> convertMetadata(Collection<GridQueryFieldMetadata> meta) {
+ List<CacheQueryFieldsMetaResult> res = new ArrayList<>();
+
+ if (meta != null) {
+ for (GridQueryFieldMetadata info : meta)
+ res.add(new CacheQueryFieldsMetaResult(info));
+ }
+
+ return res;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a0f4af95/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 9068487..2cf9988 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -577,63 +577,6 @@ public class GridJettyRestHandler extends AbstractHandler {
break;
}
- case EXECUTE_SQL_QUERY:
- case EXECUTE_SQL_FIELDS_QUERY: {
- RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
-
- restReq0.sqlQuery((String) params.get("qry"));
-
- restReq0.arguments(values("arg", params).toArray());
-
- restReq0.typeName((String) params.get("type"));
-
- String psz = (String) params.get("psz");
-
- if (psz != null)
- restReq0.pageSize(Integer.parseInt(psz));
-
- restReq0.cacheName((String)params.get("cacheName"));
-
- restReq = restReq0;
-
- break;
- }
-
- case FETCH_SQL_QUERY: {
- RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
-
- String qryId = (String) params.get("qryId");
-
- if (qryId != null)
- restReq0.queryId(Long.parseLong(qryId));
-
- String psz = (String) params.get("psz");
-
- if (psz != null)
- restReq0.pageSize(Integer.parseInt(psz));
-
- restReq0.cacheName((String)params.get("cacheName"));
-
- restReq = restReq0;
-
- break;
- }
-
- case CLOSE_SQL_QUERY: {
- RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
-
- String qryId = (String) params.get("qryId");
-
- if (qryId != null)
- restReq0.queryId(Long.parseLong(qryId));
-
- restReq0.cacheName((String)params.get("cacheName"));
-
- restReq = restReq0;
-
- break;
- }
-
case RUN_SCRIPT: {
RestRunScriptRequest restReq0 = new RestRunScriptRequest();