From 1c7579681748c7b483607d6efaed6331a1b9cf91 Mon Sep 17 00:00:00 2001 From: Rajat Khandelwal Date: Mon, 6 Apr 2015 18:25:22 +0530 Subject: [PATCH 1/3] add single-partition command added --- .../commands/LensDimensionTableCommands.java | 6 +- .../lens/cli/commands/LensFactCommands.java | 8 +- .../apache/lens/cli/TestLensFactCommands.java | 16 ++ .../lens/client/LensMetadataClient.java | 256 ++++++++++-------- .../lens/cube/parse/CubeQueryConfUtil.java | 1 + .../lens/cube/parse/StorageTableResolver.java | 2 + .../metastore/CubeMetastoreServiceImpl.java | 1 + .../server/metastore/MetastoreResource.java | 28 +- 8 files changed, 196 insertions(+), 122 deletions(-) diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java index 5a3fef38f..c61be09a3 100644 --- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java +++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java @@ -333,7 +333,7 @@ public String dropAllPartitionsOfDim( * @param specPair the spec pair * @return the string */ - @CliCommand(value = "dimtable add partition", help = "add a partition to dim table") + @CliCommand(value = "dimtable add single-partition", help = "add a partition to dim table") public String addPartitionToDimTable( @CliOption(key = {"", "table"}, mandatory = true, help = " " + " ") String specPair) { @@ -342,7 +342,7 @@ public String addPartitionToDimTable( APIResult result; if (pair.length != 3) { return "Syntax error, please try in following " - + "format. dimtable add partition "; + + "format. dimtable add single-partition
"; } File f = new File(pair[2]); @@ -373,7 +373,7 @@ public String addPartitionsToDimTable( APIResult result; if (pair.length != 3) { return "Syntax error, please try in following " - + "format. dimtable add partition
"; + + "format. dimtable add partitions
"; } File f = new File(pair[2]); 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 47686e905..a69d3611e 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 @@ -311,7 +311,7 @@ public String dropAllPartitionsOfFact( * @param specPair the spec pair * @return the string */ - @CliCommand(value = "fact add partition", help = "add a partition to fact table") + @CliCommand(value = "fact add single-partition", help = "add a partition to fact table") public String addPartitionToFact( @CliOption(key = {"", "table"}, mandatory = true, help = "
") String specPair) { @@ -319,7 +319,8 @@ public String addPartitionToFact( String[] pair = Iterables.toArray(parts, String.class); APIResult result; if (pair.length != 3) { - return "Syntax error, please try in following " + "format. fact add partition
"; + return "Syntax error, please try in following " + "format. fact add single-partition " + + "
"; } File f = new File(pair[2]); @@ -349,7 +350,8 @@ public String addPartitionsToFact( String[] pair = Iterables.toArray(parts, String.class); APIResult result; if (pair.length != 3) { - return "Syntax error, please try in following " + "format. fact add partition
"; + return "Syntax error, please try in following " + + "format. fact add partitions
"; } File f = new File(pair[2]); 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 f22515508..f056bb786 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 @@ -199,6 +199,22 @@ private void testFactPartitionActions() { Assert.fail("Unable to locate the storage part file for adding new storage to fact table fact1"); } verifyAndDeletePartitions(); + + // Wrong files: + try { + command.addPartitionToFact("fact1 " + FACT_LOCAL + " " + new File( + TestLensFactCommands.class.getClassLoader().getResource("fact1-local-parts.xml").toURI()).getAbsolutePath()); + Assert.fail("Should fail"); + } catch (Throwable t) { + // pass + } + try { + command.addPartitionsToFact("fact1 " + FACT_LOCAL + " " + new File( + TestLensFactCommands.class.getClassLoader().getResource("fact1-local-part.xml").toURI()).getAbsolutePath()); + Assert.fail("Should fail"); + } catch (Throwable t) { + // pass + } } private void verifyAndDeletePartitions() { diff --git a/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java b/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java index 3462dc3d6..ad79cf2a1 100644 --- a/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java +++ b/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java @@ -186,23 +186,22 @@ public APIResult createCube(XCube cube) { return result; } - private Object readFromXML(String filename) throws JAXBException, IOException { + private T readFromXML(String filename) throws JAXBException, IOException { if (filename.startsWith("/")) { - return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(new File(filename))).getValue(); + return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(new File(filename))).getValue(); } else { // load from classpath InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); if (file == null) { throw new IOException("File not found:" + filename); } - return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(file)).getValue(); + return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(file)).getValue(); } } public APIResult createCube(String cubeSpec) { - XCube cube; try { - cube = (XCube) readFromXML(cubeSpec); + return createCube(this.readFromXML(cubeSpec)); } catch (JAXBException e) { LOG.info("Unmarshalling error:", e); return new APIResult(Status.FAILED, "Unmarshalling failed"); @@ -210,7 +209,6 @@ public APIResult createCube(String cubeSpec) { LOG.info("File error:", e); return new APIResult(Status.FAILED, "File not found"); } - return createCube(cube); } public APIResult updateCube(String cubeName, XCube cube) { @@ -223,9 +221,8 @@ public APIResult updateCube(String cubeName, XCube cube) { } public APIResult updateCube(String cubeName, String cubeSpec) { - XCube cube; try { - cube = (XCube) readFromXML(cubeSpec); + return updateCube(cubeName, this.readFromXML(cubeSpec)); } catch (JAXBException e) { LOG.info("Unmarshalling error:", e); return new APIResult(Status.FAILED, "Unmarshalling failed"); @@ -233,7 +230,6 @@ public APIResult updateCube(String cubeName, String cubeSpec) { LOG.info("File error:", e); return new APIResult(Status.FAILED, "File not found"); } - return updateCube(cubeName, cube); } public XCube getCube(String cubeName) { @@ -279,12 +275,15 @@ public APIResult createDimension(XDimension dimension) { } public APIResult createDimension(String dimSpec) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimensions") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(dimSpec)), APIResult.class); - return result; + try { + return createDimension(this.readFromXML(dimSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public APIResult updateDimension(String dimName, XDimension dimension) { @@ -297,12 +296,15 @@ public APIResult updateDimension(String dimName, XDimension dimension) { } public APIResult updateDimension(String dimName, String dimSpec) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimensions").path(dimName) - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .put(Entity.xml(getContent(dimSpec)), APIResult.class); - return result; + try { + return updateDimension(dimName, this.readFromXML(dimSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public XDimension getDimension(String dimName) { @@ -342,12 +344,15 @@ public APIResult createNewStorage(XStorage storage) { public APIResult createNewStorage(String storage) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("storages") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(storage)), APIResult.class); - return result; + try { + return createNewStorage(this.readFromXML(storage)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public APIResult dropAllStorages() { @@ -369,12 +374,15 @@ public APIResult updateStorage(String storageName, XStorage storage) { } public APIResult updateStorage(String storageName, String storage) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("storages").path(storageName) - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .put(Entity.xml(getContent(storage)), APIResult.class); - return result; + try { + return updateStorage(storageName, this.readFromXML(storage)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public XStorage getStorage(String storageName) { @@ -452,18 +460,15 @@ public APIResult createFactTable(XFactTable f) { } public APIResult createFactTable(String factSpec) { - WebTarget target = getMetastoreWebTarget(); - FormDataMultiPart mp = new FormDataMultiPart(); - mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid") - .build(), this.connection.getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); - mp.bodyPart(new FormDataBodyPart( - FormDataContentDisposition.name("fact").fileName("fact").build(), - getContent(factSpec), MediaType.APPLICATION_XML_TYPE)); - APIResult result = target.path("facts") - .request(MediaType.APPLICATION_XML_TYPE) - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), - APIResult.class); - return result; + try { + return createFactTable(this.readFromXML(factSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } private String getContent(String path) { @@ -499,12 +504,15 @@ public APIResult updateFactTable(String factName, XFactTable table) { } public APIResult updateFactTable(String factName, String table) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("facts").path(factName) - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML_TYPE) - .put(Entity.xml(getContent(table)), APIResult.class); - return result; + try { + return updateFactTable(factName, this.readFromXML(table)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public APIResult dropFactTable(String factName, boolean cascade) { @@ -548,13 +556,16 @@ public APIResult addStorageToFactTable(String factname, XStorageTableElement sto return result; } - public APIResult addStorageToFactTable(String factname, String storage) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("facts").path(factname).path("storages") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(storage)), APIResult.class); - return result; + public APIResult addStorageToFactTable(String factname, String storageSpec) { + try { + return addStorageToFactTable(factname, this.readFromXML(storageSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public APIResult dropStorageFromFactTable(String factName, String storageName) { @@ -649,19 +660,15 @@ public APIResult createDimensionTable(XDimensionTable table) { } public APIResult createDimensionTable(String tableXml) { - WebTarget target = getMetastoreWebTarget(); - - FormDataMultiPart mp = new FormDataMultiPart(); - mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), - this.connection.getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); - mp.bodyPart(new FormDataBodyPart( - FormDataContentDisposition.name("dimensionTable").fileName("dimtable").build(), - getContent(tableXml), MediaType.APPLICATION_XML_TYPE)); - - APIResult result = target.path("dimtables") - .request(MediaType.APPLICATION_XML) - .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class); - return result; + try { + return createDimensionTable(this.readFromXML(tableXml)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } @@ -676,12 +683,18 @@ public APIResult updateDimensionTable(XDimensionTable table) { } public APIResult updateDimensionTable(String dimTblName, String dimSpec) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimtables").path(dimTblName) - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .put(Entity.xml(getContent(dimSpec)), APIResult.class); - return result; + try { + XDimensionTable dimensionTable = readFromXML(dimSpec); + dimensionTable.setTableName(dimTblName); + return updateDimensionTable(dimensionTable); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } + } public APIResult dropDimensionTable(String table, boolean cascade) { @@ -728,12 +741,15 @@ public APIResult addStorageToDimTable(String dimTblName, XStorageTableElement ta } public APIResult addStorageToDimTable(String dimTblName, String table) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimtables").path(dimTblName).path("storages") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(table)), APIResult.class); - return result; + try { + return addStorageToDimTable(dimTblName, this.readFromXML(table)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public XStorageTableElement getStorageOfDimensionTable(String dimTblName, String storage) { @@ -825,15 +841,18 @@ public APIResult addPartitionToDimensionTable(String dimTblName, String storage, } public APIResult addPartitionToDimensionTable(String dimTblName, String storage, - String partition) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimtables").path(dimTblName) - .path("storages").path(storage).path("partition") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(partition)), APIResult.class); - return result; + String partitionSpec) { + try { + return addPartitionToDimensionTable(dimTblName, storage, (XPartition) readFromXML(partitionSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } + public APIResult addPartitionsToDimensionTable(String dimTblName, String storage, XPartitionList partitions) { WebTarget target = getMetastoreWebTarget(); @@ -846,14 +865,16 @@ public APIResult addPartitionsToDimensionTable(String dimTblName, String storage } public APIResult addPartitionsToDimensionTable(String dimTblName, String storage, - String partitions) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("dimtables").path(dimTblName) - .path("storages").path(storage).path("partitions") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(partitions)), APIResult.class); - return result; + String partitionsSpec) { + try { + return addPartitionsToDimensionTable(dimTblName, storage, (XPartitionList) readFromXML(partitionsSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } public APIResult addPartitionToFactTable(String fact, String storage, @@ -868,15 +889,18 @@ public APIResult addPartitionToFactTable(String fact, String storage, } public APIResult addPartitionToFactTable(String fact, String storage, - String partition) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("facts").path(fact) - .path("storages").path(storage).path("partition") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(partition)), APIResult.class); - return result; + String partitionSpec) { + try { + return addPartitionToFactTable(fact, storage, (XPartition) readFromXML(partitionSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } + public APIResult addPartitionsToFactTable(String fact, String storage, XPartitionList partitions) { WebTarget target = getMetastoreWebTarget(); @@ -889,13 +913,15 @@ public APIResult addPartitionsToFactTable(String fact, String storage, } public APIResult addPartitionsToFactTable(String fact, String storage, - String partitions) { - WebTarget target = getMetastoreWebTarget(); - APIResult result = target.path("facts").path(fact) - .path("storages").path(storage).path("partitions") - .queryParam("sessionid", this.connection.getSessionHandle()) - .request(MediaType.APPLICATION_XML) - .post(Entity.xml(getContent(partitions)), APIResult.class); - return result; + String partitionsSpec) { + try { + return addPartitionsToFactTable(fact, storage, (XPartitionList) readFromXML(partitionsSpec)); + } catch (JAXBException e) { + LOG.info("Unmarshalling error:", e); + return new APIResult(Status.FAILED, "Unmarshalling failed"); + } catch (IOException e) { + LOG.info("File error:", e); + return new APIResult(Status.FAILED, "File not found"); + } } } diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryConfUtil.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryConfUtil.java index a6374f654..19ab11acc 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryConfUtil.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/CubeQueryConfUtil.java @@ -43,6 +43,7 @@ private CubeQueryConfUtil() { public static final String VALID_STORAGE_DIM_TABLES = "lens.cube.query.valid." + "dim.storgaetables"; public static final String DRIVER_SUPPORTED_STORAGES = "lens.cube.query.driver." + "supported.storages"; public static final String FAIL_QUERY_ON_PARTIAL_DATA = "lens.cube.query.fail.if.data.partial"; + public static final String SKIP_FACTS_ON_NO_DATA = "lens.cube.facts.skip.on.no.data"; public static final String NON_EXISTING_PARTITIONS = "lens.cube.query.nonexisting.partitions"; public static final String ENABLE_MULTI_TABLE_SELECT = "lens.cube.query.enable.multi.table.select"; public static final String QUERY_MAX_INTERVAL = "lens.cube.query.max.interval"; diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java index 6e63483dc..01a4d859e 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java @@ -54,6 +54,7 @@ class StorageTableResolver implements ContextRewriter { private final boolean allStoragesSupported; CubeMetastoreClient client; private final boolean failOnPartialData; + private final boolean skipOnNoData; private final List validDimTables; private final Map>> validStorageMap = new HashMap>>(); @@ -85,6 +86,7 @@ public StorageTableResolver(Configuration conf) { this.supportedStorages = getSupportedStorages(conf); this.allStoragesSupported = (supportedStorages == null); this.failOnPartialData = conf.getBoolean(CubeQueryConfUtil.FAIL_QUERY_ON_PARTIAL_DATA, false); + this.skipOnNoData = conf.getBoolean(CubeQueryConfUtil.SKIP_FACTS_ON_NO_DATA, false); String str = conf.get(CubeQueryConfUtil.VALID_STORAGE_DIM_TABLES); validDimTables = StringUtils.isBlank(str) ? null : Arrays.asList(StringUtils.split(str.toLowerCase(), ",")); this.processTimePartCol = conf.get(CubeQueryConfUtil.PROCESS_TIME_PART_COL); diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java index 185972eed..bcc5f99d6 100644 --- a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java @@ -56,6 +56,7 @@ synchronized CubeMetastoreClient getClient(LensSessionHandle sessionid) throws L } + /** * Get current database used by the CubeMetastoreClient * 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 06c352e50..d7f57bbaa 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 @@ -49,6 +49,7 @@ public class MetastoreResource { public static final APIResult SUCCESS = new APIResult(Status.SUCCEEDED, ""); public static final ObjectFactory X_CUBE_OBJECT_FACTORY = new ObjectFactory(); + public CubeMetastoreService getSvc() { return (CubeMetastoreService) LensServices.get().getService("metastore"); } @@ -59,6 +60,30 @@ private void checkSessionId(LensSessionHandle sessionHandle) { } } + // private T checkValidity(JAXBElement object) { + // String NS = "http://www.w3.org/2001/XMLSchema"; + // try { + // JAXBContext jaxbContext = JAXBContext.newInstance(object.getDeclaredType()); + // SchemaFactory schemaFactory = SchemaFactory.newInstance(NS); + // Schema schema = schemaFactory.newSchema(getClass().getResource("/cube-0.1.xsd")); + // Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + // unmarshaller.setSchema(schema); + // unmarshaller.setEventHandler(new ValidationEventHandler() { + // public boolean handleEvent(ValidationEvent event) { + // System.out.println(event); + // return false; + // } + // }); + // Marshaller marshaller = jaxbContext.createMarshaller(); + // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + // ByteArrayOutputStream stream = new ByteArrayOutputStream(); + // marshaller.marshal(object, stream); + // return (T) unmarshaller.unmarshal(new StringReader(stream.toString())); + // } catch (Exception e) { + // throw new BadRequestException(e); + // } + // } + private void checkNonNullArgs(String message, Object... args) { for (Object arg : args) { if (arg == null) { @@ -1070,7 +1095,7 @@ public APIResult addPartitionToFactStorage(@QueryParam("sessionid") LensSessionH @PathParam("storage") String storage, XPartition partition) { checkSessionId(sessionid); - checkNonNullArgs("Partition is null", partition); + // checkValidity(X_CUBE_OBJECT_FACTORY.createXPartition(partition)); try { getSvc().addPartitionToFactStorage(sessionid, factName, storage, partition); } catch (LensException exc) { @@ -1098,6 +1123,7 @@ public APIResult addPartitionsToFactStorage(@QueryParam("sessionid") LensSession @PathParam("storage") String storage, XPartitionList partitions) { checkSessionId(sessionid); + // checkValidity(X_CUBE_OBJECT_FACTORY.createXPartitionList(partitions)); checkNonNullArgs("Partition List is null", partitions); try { getSvc().addPartitionsToFactStorage(sessionid, factName, storage, partitions); From e47600b9f0af39d66df5daf8dcda2380d4da816e Mon Sep 17 00:00:00 2001 From: Rajat Khandelwal Date: Mon, 6 Apr 2015 18:37:45 +0530 Subject: [PATCH 2/3] df --- .../commands/LensDimensionTableCommands.java | 6 +- .../lens/cli/commands/LensFactCommands.java | 8 +- .../apache/lens/cli/TestLensFactCommands.java | 16 -- .../lens/client/LensMetadataClient.java | 256 ++++++++---------- .../metastore/CubeMetastoreServiceImpl.java | 1 - .../server/metastore/MetastoreResource.java | 28 +- 6 files changed, 122 insertions(+), 193 deletions(-) diff --git a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java index c61be09a3..5a3fef38f 100644 --- a/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java +++ b/lens-cli/src/main/java/org/apache/lens/cli/commands/LensDimensionTableCommands.java @@ -333,7 +333,7 @@ public String dropAllPartitionsOfDim( * @param specPair the spec pair * @return the string */ - @CliCommand(value = "dimtable add single-partition", help = "add a partition to dim table") + @CliCommand(value = "dimtable add partition", help = "add a partition to dim table") public String addPartitionToDimTable( @CliOption(key = {"", "table"}, mandatory = true, help = " " + " ") String specPair) { @@ -342,7 +342,7 @@ public String addPartitionToDimTable( APIResult result; if (pair.length != 3) { return "Syntax error, please try in following " - + "format. dimtable add single-partition
"; + + "format. dimtable add partition
"; } File f = new File(pair[2]); @@ -373,7 +373,7 @@ public String addPartitionsToDimTable( APIResult result; if (pair.length != 3) { return "Syntax error, please try in following " - + "format. dimtable add partitions
"; + + "format. dimtable add partition
"; } File f = new File(pair[2]); 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 a69d3611e..47686e905 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 @@ -311,7 +311,7 @@ public String dropAllPartitionsOfFact( * @param specPair the spec pair * @return the string */ - @CliCommand(value = "fact add single-partition", help = "add a partition to fact table") + @CliCommand(value = "fact add partition", help = "add a partition to fact table") public String addPartitionToFact( @CliOption(key = {"", "table"}, mandatory = true, help = "
") String specPair) { @@ -319,8 +319,7 @@ public String addPartitionToFact( String[] pair = Iterables.toArray(parts, String.class); APIResult result; if (pair.length != 3) { - return "Syntax error, please try in following " + "format. fact add single-partition " - + "
"; + return "Syntax error, please try in following " + "format. fact add partition
"; } File f = new File(pair[2]); @@ -350,8 +349,7 @@ public String addPartitionsToFact( String[] pair = Iterables.toArray(parts, String.class); APIResult result; if (pair.length != 3) { - return "Syntax error, please try in following " - + "format. fact add partitions
"; + return "Syntax error, please try in following " + "format. fact add partition
"; } File f = new File(pair[2]); 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 f056bb786..f22515508 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 @@ -199,22 +199,6 @@ private void testFactPartitionActions() { Assert.fail("Unable to locate the storage part file for adding new storage to fact table fact1"); } verifyAndDeletePartitions(); - - // Wrong files: - try { - command.addPartitionToFact("fact1 " + FACT_LOCAL + " " + new File( - TestLensFactCommands.class.getClassLoader().getResource("fact1-local-parts.xml").toURI()).getAbsolutePath()); - Assert.fail("Should fail"); - } catch (Throwable t) { - // pass - } - try { - command.addPartitionsToFact("fact1 " + FACT_LOCAL + " " + new File( - TestLensFactCommands.class.getClassLoader().getResource("fact1-local-part.xml").toURI()).getAbsolutePath()); - Assert.fail("Should fail"); - } catch (Throwable t) { - // pass - } } private void verifyAndDeletePartitions() { diff --git a/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java b/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java index ad79cf2a1..3462dc3d6 100644 --- a/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java +++ b/lens-client/src/main/java/org/apache/lens/client/LensMetadataClient.java @@ -186,22 +186,23 @@ public APIResult createCube(XCube cube) { return result; } - private T readFromXML(String filename) throws JAXBException, IOException { + private Object readFromXML(String filename) throws JAXBException, IOException { if (filename.startsWith("/")) { - return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(new File(filename))).getValue(); + return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(new File(filename))).getValue(); } else { // load from classpath InputStream file = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); if (file == null) { throw new IOException("File not found:" + filename); } - return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(file)).getValue(); + return ((JAXBElement) JAXB_UNMARSHALLER.unmarshal(file)).getValue(); } } public APIResult createCube(String cubeSpec) { + XCube cube; try { - return createCube(this.readFromXML(cubeSpec)); + cube = (XCube) readFromXML(cubeSpec); } catch (JAXBException e) { LOG.info("Unmarshalling error:", e); return new APIResult(Status.FAILED, "Unmarshalling failed"); @@ -209,6 +210,7 @@ public APIResult createCube(String cubeSpec) { LOG.info("File error:", e); return new APIResult(Status.FAILED, "File not found"); } + return createCube(cube); } public APIResult updateCube(String cubeName, XCube cube) { @@ -221,8 +223,9 @@ public APIResult updateCube(String cubeName, XCube cube) { } public APIResult updateCube(String cubeName, String cubeSpec) { + XCube cube; try { - return updateCube(cubeName, this.readFromXML(cubeSpec)); + cube = (XCube) readFromXML(cubeSpec); } catch (JAXBException e) { LOG.info("Unmarshalling error:", e); return new APIResult(Status.FAILED, "Unmarshalling failed"); @@ -230,6 +233,7 @@ public APIResult updateCube(String cubeName, String cubeSpec) { LOG.info("File error:", e); return new APIResult(Status.FAILED, "File not found"); } + return updateCube(cubeName, cube); } public XCube getCube(String cubeName) { @@ -275,15 +279,12 @@ public APIResult createDimension(XDimension dimension) { } public APIResult createDimension(String dimSpec) { - try { - return createDimension(this.readFromXML(dimSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimensions") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(dimSpec)), APIResult.class); + return result; } public APIResult updateDimension(String dimName, XDimension dimension) { @@ -296,15 +297,12 @@ public APIResult updateDimension(String dimName, XDimension dimension) { } public APIResult updateDimension(String dimName, String dimSpec) { - try { - return updateDimension(dimName, this.readFromXML(dimSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimensions").path(dimName) + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .put(Entity.xml(getContent(dimSpec)), APIResult.class); + return result; } public XDimension getDimension(String dimName) { @@ -344,15 +342,12 @@ public APIResult createNewStorage(XStorage storage) { public APIResult createNewStorage(String storage) { - try { - return createNewStorage(this.readFromXML(storage)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("storages") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(storage)), APIResult.class); + return result; } public APIResult dropAllStorages() { @@ -374,15 +369,12 @@ public APIResult updateStorage(String storageName, XStorage storage) { } public APIResult updateStorage(String storageName, String storage) { - try { - return updateStorage(storageName, this.readFromXML(storage)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("storages").path(storageName) + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .put(Entity.xml(getContent(storage)), APIResult.class); + return result; } public XStorage getStorage(String storageName) { @@ -460,15 +452,18 @@ public APIResult createFactTable(XFactTable f) { } public APIResult createFactTable(String factSpec) { - try { - return createFactTable(this.readFromXML(factSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + FormDataMultiPart mp = new FormDataMultiPart(); + mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid") + .build(), this.connection.getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); + mp.bodyPart(new FormDataBodyPart( + FormDataContentDisposition.name("fact").fileName("fact").build(), + getContent(factSpec), MediaType.APPLICATION_XML_TYPE)); + APIResult result = target.path("facts") + .request(MediaType.APPLICATION_XML_TYPE) + .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), + APIResult.class); + return result; } private String getContent(String path) { @@ -504,15 +499,12 @@ public APIResult updateFactTable(String factName, XFactTable table) { } public APIResult updateFactTable(String factName, String table) { - try { - return updateFactTable(factName, this.readFromXML(table)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("facts").path(factName) + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML_TYPE) + .put(Entity.xml(getContent(table)), APIResult.class); + return result; } public APIResult dropFactTable(String factName, boolean cascade) { @@ -556,16 +548,13 @@ public APIResult addStorageToFactTable(String factname, XStorageTableElement sto return result; } - public APIResult addStorageToFactTable(String factname, String storageSpec) { - try { - return addStorageToFactTable(factname, this.readFromXML(storageSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + public APIResult addStorageToFactTable(String factname, String storage) { + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("facts").path(factname).path("storages") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(storage)), APIResult.class); + return result; } public APIResult dropStorageFromFactTable(String factName, String storageName) { @@ -660,15 +649,19 @@ public APIResult createDimensionTable(XDimensionTable table) { } public APIResult createDimensionTable(String tableXml) { - try { - return createDimensionTable(this.readFromXML(tableXml)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + + FormDataMultiPart mp = new FormDataMultiPart(); + mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), + this.connection.getSessionHandle(), MediaType.APPLICATION_XML_TYPE)); + mp.bodyPart(new FormDataBodyPart( + FormDataContentDisposition.name("dimensionTable").fileName("dimtable").build(), + getContent(tableXml), MediaType.APPLICATION_XML_TYPE)); + + APIResult result = target.path("dimtables") + .request(MediaType.APPLICATION_XML) + .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), APIResult.class); + return result; } @@ -683,18 +676,12 @@ public APIResult updateDimensionTable(XDimensionTable table) { } public APIResult updateDimensionTable(String dimTblName, String dimSpec) { - try { - XDimensionTable dimensionTable = readFromXML(dimSpec); - dimensionTable.setTableName(dimTblName); - return updateDimensionTable(dimensionTable); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } - + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimtables").path(dimTblName) + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .put(Entity.xml(getContent(dimSpec)), APIResult.class); + return result; } public APIResult dropDimensionTable(String table, boolean cascade) { @@ -741,15 +728,12 @@ public APIResult addStorageToDimTable(String dimTblName, XStorageTableElement ta } public APIResult addStorageToDimTable(String dimTblName, String table) { - try { - return addStorageToDimTable(dimTblName, this.readFromXML(table)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimtables").path(dimTblName).path("storages") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(table)), APIResult.class); + return result; } public XStorageTableElement getStorageOfDimensionTable(String dimTblName, String storage) { @@ -841,18 +825,15 @@ public APIResult addPartitionToDimensionTable(String dimTblName, String storage, } public APIResult addPartitionToDimensionTable(String dimTblName, String storage, - String partitionSpec) { - try { - return addPartitionToDimensionTable(dimTblName, storage, (XPartition) readFromXML(partitionSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + String partition) { + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimtables").path(dimTblName) + .path("storages").path(storage).path("partition") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(partition)), APIResult.class); + return result; } - public APIResult addPartitionsToDimensionTable(String dimTblName, String storage, XPartitionList partitions) { WebTarget target = getMetastoreWebTarget(); @@ -865,16 +846,14 @@ public APIResult addPartitionsToDimensionTable(String dimTblName, String storage } public APIResult addPartitionsToDimensionTable(String dimTblName, String storage, - String partitionsSpec) { - try { - return addPartitionsToDimensionTable(dimTblName, storage, (XPartitionList) readFromXML(partitionsSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + String partitions) { + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("dimtables").path(dimTblName) + .path("storages").path(storage).path("partitions") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(partitions)), APIResult.class); + return result; } public APIResult addPartitionToFactTable(String fact, String storage, @@ -889,18 +868,15 @@ public APIResult addPartitionToFactTable(String fact, String storage, } public APIResult addPartitionToFactTable(String fact, String storage, - String partitionSpec) { - try { - return addPartitionToFactTable(fact, storage, (XPartition) readFromXML(partitionSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + String partition) { + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("facts").path(fact) + .path("storages").path(storage).path("partition") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(partition)), APIResult.class); + return result; } - public APIResult addPartitionsToFactTable(String fact, String storage, XPartitionList partitions) { WebTarget target = getMetastoreWebTarget(); @@ -913,15 +889,13 @@ public APIResult addPartitionsToFactTable(String fact, String storage, } public APIResult addPartitionsToFactTable(String fact, String storage, - String partitionsSpec) { - try { - return addPartitionsToFactTable(fact, storage, (XPartitionList) readFromXML(partitionsSpec)); - } catch (JAXBException e) { - LOG.info("Unmarshalling error:", e); - return new APIResult(Status.FAILED, "Unmarshalling failed"); - } catch (IOException e) { - LOG.info("File error:", e); - return new APIResult(Status.FAILED, "File not found"); - } + String partitions) { + WebTarget target = getMetastoreWebTarget(); + APIResult result = target.path("facts").path(fact) + .path("storages").path(storage).path("partitions") + .queryParam("sessionid", this.connection.getSessionHandle()) + .request(MediaType.APPLICATION_XML) + .post(Entity.xml(getContent(partitions)), APIResult.class); + return result; } } diff --git a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java index bcc5f99d6..185972eed 100644 --- a/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java +++ b/lens-server/src/main/java/org/apache/lens/server/metastore/CubeMetastoreServiceImpl.java @@ -56,7 +56,6 @@ synchronized CubeMetastoreClient getClient(LensSessionHandle sessionid) throws L } - /** * Get current database used by the CubeMetastoreClient * 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 d7f57bbaa..06c352e50 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 @@ -49,7 +49,6 @@ public class MetastoreResource { public static final APIResult SUCCESS = new APIResult(Status.SUCCEEDED, ""); public static final ObjectFactory X_CUBE_OBJECT_FACTORY = new ObjectFactory(); - public CubeMetastoreService getSvc() { return (CubeMetastoreService) LensServices.get().getService("metastore"); } @@ -60,30 +59,6 @@ private void checkSessionId(LensSessionHandle sessionHandle) { } } - // private T checkValidity(JAXBElement object) { - // String NS = "http://www.w3.org/2001/XMLSchema"; - // try { - // JAXBContext jaxbContext = JAXBContext.newInstance(object.getDeclaredType()); - // SchemaFactory schemaFactory = SchemaFactory.newInstance(NS); - // Schema schema = schemaFactory.newSchema(getClass().getResource("/cube-0.1.xsd")); - // Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - // unmarshaller.setSchema(schema); - // unmarshaller.setEventHandler(new ValidationEventHandler() { - // public boolean handleEvent(ValidationEvent event) { - // System.out.println(event); - // return false; - // } - // }); - // Marshaller marshaller = jaxbContext.createMarshaller(); - // marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - // ByteArrayOutputStream stream = new ByteArrayOutputStream(); - // marshaller.marshal(object, stream); - // return (T) unmarshaller.unmarshal(new StringReader(stream.toString())); - // } catch (Exception e) { - // throw new BadRequestException(e); - // } - // } - private void checkNonNullArgs(String message, Object... args) { for (Object arg : args) { if (arg == null) { @@ -1095,7 +1070,7 @@ public APIResult addPartitionToFactStorage(@QueryParam("sessionid") LensSessionH @PathParam("storage") String storage, XPartition partition) { checkSessionId(sessionid); - // checkValidity(X_CUBE_OBJECT_FACTORY.createXPartition(partition)); + checkNonNullArgs("Partition is null", partition); try { getSvc().addPartitionToFactStorage(sessionid, factName, storage, partition); } catch (LensException exc) { @@ -1123,7 +1098,6 @@ public APIResult addPartitionsToFactStorage(@QueryParam("sessionid") LensSession @PathParam("storage") String storage, XPartitionList partitions) { checkSessionId(sessionid); - // checkValidity(X_CUBE_OBJECT_FACTORY.createXPartitionList(partitions)); checkNonNullArgs("Partition List is null", partitions); try { getSvc().addPartitionsToFactStorage(sessionid, factName, storage, partitions); From 59b66760ea1e5828ec3eba3c0ed66fee749ab591 Mon Sep 17 00:00:00 2001 From: Rajat Khandelwal Date: Mon, 6 Apr 2015 19:33:39 +0530 Subject: [PATCH 3/3] all changes, test cases next --- .../lens/cube/parse/StorageTableResolver.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java index 01a4d859e..160068f80 100644 --- a/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java +++ b/lens-cube/src/main/java/org/apache/lens/cube/parse/StorageTableResolver.java @@ -193,7 +193,7 @@ private void resolveDimStorageTablesAndPartitions(CubeQueryContext cubeql) throw } else { LOG.info("Partition " + StorageConstants.LATEST_PARTITION_VALUE + " does not exist on " + tableName); } - if (!failOnPartialData || foundPart) { + if ((!skipOnNoData && !failOnPartialData) || foundPart) { storageTables.add(tableName); String whereClause = StorageUtil.getWherePartClause(dim.getTimedDimension(), null, @@ -327,7 +327,15 @@ private void resolveFactStoragePartitions(CubeQueryContext cubeql) throws Semant noPartsForRange = true; continue; } - cfact.incrementPartsQueried(rangeParts.size()); + if (skipOnNoData) { + for (FactPartition part : rangeParts) { + if (part.found()) { + cfact.incrementPartsQueried(1); + } + } + } else { + cfact.incrementPartsQueried(rangeParts.size()); + } answeringParts.addAll(rangeParts); cfact.getPartsQueried().addAll(rangeParts); cfact.getRangeToWhereClause().put(range, rangeWriter.getTimeRangeWhereClause(cubeql, @@ -514,10 +522,6 @@ private boolean getPartitions(CubeFactTable fact, Date fromDate, Date toDate, St partWhereClauseFormat)); } LOG.info("added all sub partitions blindly in pPart: " + pPart); -// if (!getPartitions(fact, dt, cal.getTime(), partCol, pPart, partitions, newset, false, -// skipStorageCauses, nonExistingParts)) { -// LOG.info("No partitions found in look ahead range"); -// } } } }