You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2017/04/20 10:36:27 UTC
lens git commit: LENS-1410 : Make the filter while getting a list of
partitions mandatory
Repository: lens
Updated Branches:
refs/heads/master cf944c10c -> de8f2ec6f
LENS-1410 : Make the filter while getting a list of partitions mandatory
Project: http://git-wip-us.apache.org/repos/asf/lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/lens/commit/de8f2ec6
Tree: http://git-wip-us.apache.org/repos/asf/lens/tree/de8f2ec6
Diff: http://git-wip-us.apache.org/repos/asf/lens/diff/de8f2ec6
Branch: refs/heads/master
Commit: de8f2ec6fa812d7d34e8d882c621f0215abe777d
Parents: cf944c1
Author: Lavkesh Lahngir <la...@linux.com>
Authored: Thu Apr 20 16:06:13 2017 +0530
Committer: Amareshwari Sriramadasu <am...@apache.org>
Committed: Thu Apr 20 16:06:13 2017 +0530
----------------------------------------------------------------------
lens-api/src/main/resources/lens-errors.conf | 7 ++++
.../lens/cli/commands/LensFactCommands.java | 2 +-
.../apache/lens/cli/TestLensFactCommands.java | 14 ++++++--
.../lens/cube/error/LensCubeErrorCode.java | 3 +-
.../server/metastore/MetastoreResource.java | 4 +++
.../server/metastore/TestMetastoreService.java | 35 ++++++++++++++++----
6 files changed, 53 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-api/src/main/resources/lens-errors.conf
----------------------------------------------------------------------
diff --git a/lens-api/src/main/resources/lens-errors.conf b/lens-api/src/main/resources/lens-errors.conf
index 94505ef..236d678 100644
--- a/lens-api/src/main/resources/lens-errors.conf
+++ b/lens-api/src/main/resources/lens-errors.conf
@@ -365,6 +365,13 @@ lensCubeErrorsForMetastore = [
httpStatusCode = ${NOT_FOUND}
errorMsg = "%s %s Not found."
}
+
+ {
+ errorCode = 3105
+ httpStatusCode = ${BAD_REQUEST}
+ errorMsg = "Partition filter can not be null or empty"
+ }
+
]
lensDriverErrors = [
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
index 9ea887a..a01d6c0 100644
--- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
+++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensFactCommands.java
@@ -191,7 +191,7 @@ public class LensFactCommands extends LogicalTableCrudCommand<XFactTable> {
public String getAllPartitionsOfFact(
@CliOption(key = {"", "fact_name"}, mandatory = true, help = "<fact_name>") String tableName,
@CliOption(key = {"", "storage_name"}, mandatory = true, help = "<storage_name>") String storageName,
- @CliOption(key = {"", "filter"}, mandatory = false, help = "<partition-filter>") String filter) {
+ @CliOption(key = {"", "filter"}, mandatory = true, help = "<partition-filter>") String filter) {
return getAllPartitions(tableName, storageName, filter);
}
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
----------------------------------------------------------------------
diff --git a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
index f176078..d31e25c 100644
--- a/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
+++ b/lens-cli/src/test/java/org/apache/lens/cli/TestLensFactCommands.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.*;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.Calendar;
import java.util.List;
import javax.ws.rs.NotFoundException;
@@ -30,6 +31,7 @@ import javax.ws.rs.NotFoundException;
import org.apache.lens.cli.commands.LensCubeCommands;
import org.apache.lens.cli.commands.LensFactCommands;
import org.apache.lens.client.LensClient;
+import org.apache.lens.cube.metadata.UpdatePeriod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
@@ -241,7 +243,10 @@ public class TestLensFactCommands extends LensCliApplicationTest {
private void testFactPartitionActions() throws URISyntaxException {
LensFactCommands command = getCommand();
verifyEmptyTimelines();
- assertTrue(command.getAllPartitionsOfFact("fact1", FACT_LOCAL, null).trim().isEmpty());
+ Calendar cal = Calendar.getInstance();
+ cal.set(2000, 01, 01);
+ String filter = "dt>'" + UpdatePeriod.HOURLY.format(cal.getTime()) + "'";
+ assertTrue(command.getAllPartitionsOfFact("fact1", FACT_LOCAL, filter).trim().isEmpty());
String singlePartPath = new File(
TestLensFactCommands.class.getClassLoader().getResource("fact1-local-part.xml").toURI()).getAbsolutePath();
String multiplePartsPath = new File(
@@ -296,7 +301,10 @@ public class TestLensFactCommands extends LensCliApplicationTest {
private void verifyAndDeletePartitions() {
List<String> timelines;
assertEquals(getCubeCommand().getLatest("sample_cube", "dt"), "2014-03-27T12:00:00:000");
- String result = command.getAllPartitionsOfFact("fact1", FACT_LOCAL, null);
+ Calendar cal = Calendar.getInstance();
+ cal.set(2000, 01, 01);
+ String filter = "dt>'" + UpdatePeriod.HOURLY.format(cal.getTime()) + "'";
+ String result = command.getAllPartitionsOfFact("fact1", FACT_LOCAL, filter);
assertTrue(result.contains("HOURLY"));
timelines = command.getTimelines("fact1", null, null, null);
assertEquals(timelines.size(), 2);
@@ -319,7 +327,7 @@ public class TestLensFactCommands extends LensCliApplicationTest {
assertEquals(command.getTimelines("fact1", FACT_LOCAL, null, "dt"), timelines);
String dropPartitionsStatus = command.dropAllPartitionsOfFact("fact1", FACT_LOCAL, null);
assertFalse(dropPartitionsStatus.contains("Syntax error, please try in following"));
- result = command.getAllPartitionsOfFact("fact1", FACT_LOCAL, null);
+ result = command.getAllPartitionsOfFact("fact1", FACT_LOCAL, filter);
assertTrue(result.trim().isEmpty());
}
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
----------------------------------------------------------------------
diff --git a/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java b/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
index d98c4c5..babe3de 100644
--- a/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
+++ b/lens-cube/src/main/java/org/apache/lens/cube/error/LensCubeErrorCode.java
@@ -63,7 +63,8 @@ public enum LensCubeErrorCode {
ERROR_IN_ENTITY_DEFINITION(3101, 100),
TIMELINE_ABSENT(3102, 100),
EXPRESSION_NOT_PARSABLE(3103, 1500),
- ENTITY_NOT_FOUND(3104, 1500);
+ ENTITY_NOT_FOUND(3104, 1500),
+ NO_PARTITION_FILTER(3105, 1500);
public LensErrorInfo getLensErrorInfo() {
return this.errorInfo;
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java b/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java
index 9ba1eb1..7451aa9 100644
--- a/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java
+++ b/lens-server/src/main/java/org/apache/lens/server/metastore/MetastoreResource.java
@@ -19,6 +19,7 @@
package org.apache.lens.server.metastore;
import static org.apache.lens.api.APIResult.*;
+import static org.apache.lens.cube.error.LensCubeErrorCode.NO_PARTITION_FILTER;
import java.util.List;
@@ -1000,6 +1001,9 @@ public class MetastoreResource {
@QueryParam("sessionid") LensSessionHandle sessionid, @PathParam("factName") String factName,
@PathParam("storage") String storage,
@QueryParam("filter") String filter) throws LensException {
+ if (filter == null || filter.isEmpty()) {
+ throw new LensException(NO_PARTITION_FILTER.getLensErrorInfo());
+ }
checkSessionId(sessionid);
return X_CUBE_OBJECT_FACTORY
.createXPartitionList(getSvc().getAllPartitionsOfFactStorage(sessionid, factName, storage, filter));
http://git-wip-us.apache.org/repos/asf/lens/blob/de8f2ec6/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java b/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java
index f6f6e77..6d32d23 100644
--- a/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java
+++ b/lens-server/src/test/java/org/apache/lens/server/metastore/TestMetastoreService.java
@@ -1954,10 +1954,19 @@ public class TestMetastoreService extends LensJerseyTest {
assertSuccess(partUpdateResult);
JAXBElement<XPartitionList> partitionsElement = target().path("metastore/facts").path(table)
- .path("storages/S1/partitions").queryParam("sessionid", lensSessionId).request(mediaType)
+ .path("storages/S1/partitions").queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.get(new GenericType<JAXBElement<XPartitionList>>() {
});
+ //Getting partitions without filter will throw an error.
+ Response res = target().path("metastore/facts").path(table).path("storages/S1/partitions")
+ .queryParam("sessionid", lensSessionId).request(mediaType).get();
+ assertEquals(res.getStatus(), 400);
+ assertEquals(res.readEntity(String.class), "Partition filter can not be null or empty");
+
+
XPartitionList partitions = partitionsElement.getValue();
assertNotNull(partitions);
assertEquals(partitions.getPartition().size(), 1);
@@ -1998,7 +2007,9 @@ public class TestMetastoreService extends LensJerseyTest {
// Verify partition was dropped
partitionsElement = target().path("metastore/facts").path(table).path("storages/S1/partitions")
- .queryParam("sessionid", lensSessionId).request(mediaType).get(new GenericType<JAXBElement<XPartitionList>>() {
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType).get(new GenericType<JAXBElement<XPartitionList>>() {
});
partitions = partitionsElement.getValue();
@@ -2523,14 +2534,18 @@ public class TestMetastoreService extends LensJerseyTest {
xp.setLocation(xp.getLocation() + "/a/b/c");
APIResult partUpdateResult = target().path("metastore/facts/").path(table).path("storages/S2/partition")
- .queryParam("sessionid", lensSessionId).request(mediaType)
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.put(Entity.entity(new GenericEntity<JAXBElement<XPartition>>(cubeObjectFactory.createXPartition(xp)){},
mediaType), APIResult.class);
assertSuccess(partUpdateResult);
JAXBElement<XPartitionList> partitionsElement = target().path("metastore/facts").path(table)
.path("storages/S2/partitions")
- .queryParam("sessionid", lensSessionId).request(mediaType)
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.get(new GenericType<JAXBElement<XPartitionList>>() {
});
@@ -2574,7 +2589,9 @@ public class TestMetastoreService extends LensJerseyTest {
// Verify partition was dropped
partitionsElement = target().path("metastore/facts").path(table).path("storages/S2/partitions")
- .queryParam("sessionid", lensSessionId).request(mediaType)
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.get(new GenericType<JAXBElement<XPartitionList>>() {
});
@@ -2629,7 +2646,9 @@ public class TestMetastoreService extends LensJerseyTest {
// Verify partition was added
partitionsElement = target().path("metastore/facts").path(table).path("storages/S2/partitions")
- .queryParam("sessionid", lensSessionId).request(mediaType)
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.get(new GenericType<JAXBElement<XPartitionList>>() {});
partitions = partitionsElement.getValue();
@@ -2646,7 +2665,9 @@ public class TestMetastoreService extends LensJerseyTest {
// Verify partition was dropped
partitionsElement = target().path("metastore/facts").path(table).path("storages/S2/partitions")
- .queryParam("sessionid", lensSessionId).request(mediaType)
+ .queryParam("sessionid", lensSessionId)
+ .queryParam("filter", "dt='" + HOURLY.format(partDate) + "'")
+ .request(mediaType)
.get(new GenericType<JAXBElement<XPartitionList>>() {});
partitions = partitionsElement.getValue();