Package org.olap4j.mdx

Examples of org.olap4j.mdx.SelectNode


                productDimension.getAxis().getLocation());
            assertEquals(
                Axis.COLUMNS,
                measuresDimension.getAxis().getLocation());

            SelectNode mdx = query.getSelect();
            String mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "{{[Product].[Drink], [Product].[Drink].Children}} ON ROWS\n"
                + "FROM [Sales]\n"
                + "WHERE {[Time].[1997].[Q3].[7]}",
                mdxString);

            // Sort the rows in ascending order.
            query.getAxis(Axis.ROWS).sort(
                SortOrder.BASC,
                nameList("Measures", "Store Sales"));

            SelectNode sortedMdx = query.getSelect();
            String sortedMdxString = sortedMdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "Order({{[Product].[Drink], [Product].[Drink].Children}}, [Measures].[Store Sales], BASC) ON ROWS\n"
                + "FROM [Sales]\n"
View Full Code Here


            query.getAxis(Axis.ROWS).addDimension(timeDimension);
            query.getAxis(Axis.COLUMNS).addDimension(measuresDimension);

            query.validate();

            SelectNode mdx = query.getSelect();
            String mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "CrossJoin([Product].[Drink].Children, "
                + "CrossJoin({[Store].[USA], "
                + "[Store].[USA].Children}, "
                + "[Time].[1997].Children)) ON ROWS\n"
                + "FROM [Sales]",
                mdxString);

            // Push down the Products dimension.
            query.getAxis(Axis.ROWS).pushDown(0);

            query.validate();

            mdx = query.getSelect();
            mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "CrossJoin({[Store].[USA], "
                + "[Store].[USA].Children}, "
                + "CrossJoin([Product].[Drink].Children, "
                + "[Time].[1997].Children)) ON ROWS\n"
                + "FROM [Sales]",
                mdxString);

            // Pull Up the Time dimension.
            query.getAxis(Axis.ROWS).pullUp(2);

            query.validate();

            mdx = query.getSelect();
            mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "CrossJoin({[Store].[USA], "
                + "[Store].[USA].Children}, "
View Full Code Here

            query.getAxis(Axis.ROWS).addDimension(storeDimension);
            query.getAxis(Axis.COLUMNS).addDimension(measuresDimension);

            query.validate();

            SelectNode mdx = query.getSelect();
            String mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "{Hierarchize({{[Store].[USA], "
                + "[Store].[USA].Children}}, POST)} ON ROWS\n"
                + "FROM [Sales]",
                mdxString);

            storeDimension.setHierarchizeMode(HierarchizeMode.PRE);

            query.validate();

            mdx = query.getSelect();
            mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "{Hierarchize({{[Store].[USA], "
                + "[Store].[USA].Children}})} ON ROWS\n"
View Full Code Here

                Axis.COLUMNS,
                measuresDimension.getAxis().getLocation());

            // These variables are important. We will evaluate those
            // to decide if there are links between the MDX and the Query
            SelectNode originalMdx = query.getSelect();
            String originalMdxString = originalMdx.toString();

            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS,\n"
                + "{{[Product].[Drink], [Product].[Drink].Children}} ON ROWS\n"
                + "FROM [Sales]",
                originalMdxString);

            // change selections
            measuresDimension.include(
                Selection.Operator.SIBLINGS,
                nameList("Measures", "Customer Count"));
            productDimension.include(
                Selection.Operator.SIBLINGS,
                nameList(
                    "Product", "All Products", "Drink", "Alcoholic Beverages"));

            // Add something to crossjoin with
            query.getAxis(Axis.ROWS).addDimension(
                query.getDimension("Gender"));
            query.getDimension("Gender").include(
                Operator.CHILDREN, nameList("Gender", "All Gender"));

            query.getAxis(null).addDimension(
                query.getDimension("Product"));

            query.validate();

            // Check if the MDX object tree is still the same
            assertEquals(originalMdxString, originalMdx.toString());
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }
    }
View Full Code Here

            //query.getAxis(Axis.ROWS).addDimension(timeDimension);
            query.getAxis(Axis.COLUMNS).addDimension(measuresDimension);

            //query.validate();

            SelectNode mdx = query.getSelect();
            String mdxString = mdx.toString();
            TestContext.assertEqualsVerbose(
                "SELECT\n"
                + "{[Measures].[Store Sales]} ON COLUMNS\n"
                + "FROM [Sales]",
                mdxString);
View Full Code Here

        OlapConnection olapConnection = getConnection();

        MdxParser mdxParser =
            olapConnection.getParserFactory().createMdxParser(olapConnection);

        SelectNode before = mdxParser.parseSelect(initialMdx);
        SelectNode after = trans.apply(before);

        // we also parse the expected MDX in order to normalize it
        // (eliminate any whitespace / capitalization differences)
        // note: CallNodes are not aware of function names, and as such
        // will be compared in a case-sensitive manner
        // (i.e. [SomeMember].Children vs [SomeMember].children are not
        // equal, even if they are equivalent in MDX)
        SelectNode expected = mdxParser.parseSelect(expectedMdx);

        // TODO: consider adding .equals() method to ParseTreeNode instead
        // of comparing strings (we could ignore case when comparing
        // function names in CallNodes ...)
        assertEquals(expected.toString(), after.toString());
    }
View Full Code Here

              }
            }
          }
          if (where) {
            mdx += ") ON COLUMNS from " + cube;
            SelectNode sn = new DefaultMdxParserImpl().parseSelect(q.getMdx());
            final Writer writer = new StringWriter();
            sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer)));
            if (StringUtils.isNotBlank(writer.toString())) {
              mdx += "\r\nWHERE " + writer.toString();
            }
            System.out.println("Executing... :" + mdx);
            olapQueryService.executeMdx(queryName, mdx);
View Full Code Here

    String mdx = getMdx();
    try {

      if (mdx != null && mdx.length() > 0 && mdx.toUpperCase().contains("FROM")) {
        SelectNode select =
            mdxParser.parseSelect(getMdx());
        select = mdxValidator.validateSelect(select);
        CubeType cubeType = (CubeType) select.getFrom().getType();
        return cubeType.getCube();
      }
    } catch (Exception e) {
      LOG.debug("Parsing MDX to get the Cube failed. Using fallback scenario.", e);
    }
View Full Code Here

      CellSet cs = queryContext.getOlapResult();
      SaikuCube cube = query.getCube();
      final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnection());
      stmt = con.createStatement();

      SelectNode sn = new DefaultMdxParserImpl().parseSelect(query.getMdx());
      String select = null;
      StringBuilder buf = new StringBuilder();
      if (sn.getWithList() != null && sn.getWithList().size() > 0) {
        buf.append("WITH \n");
        StringWriter sw = new StringWriter();
        ParseTreeWriter ptw = new ParseTreeWriter(sw);
        final PrintWriter pw = ptw.getPrintWriter();
        for (ParseTreeNode with : sn.getWithList()) {
          with.unparse(ptw);
          pw.println();
        }
        buf.append(sw.toString());
      }

      buf.append("SELECT (");
      for (int i = 0; i < cellPosition.size(); i++) {
        List<Member> members = cs.getAxes().get(i).getPositions().get(cellPosition.get(i)).getMembers();
        for (int k = 0; k < members.size(); k++) {
          Member m = members.get(k);
          if (k > 0 || i > 0) {
            buf.append(", ");
          }
          buf.append(m.getUniqueName());
        }
      }
      buf.append(") ON COLUMNS \r\n");
      buf.append("FROM [").append(cube.getName()).append("]\r\n");


      final Writer writer = new StringWriter();
      sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer)));
      if (StringUtils.isNotBlank(writer.toString())) {
        buf.append("WHERE ").append(writer.toString());
      }
      select = buf.toString();
      if (maxrows > 0) {
View Full Code Here

  public String getMdx() {
    final Writer writer = new StringWriter();
    if (SaikuProperties.OLAPCONVERTQUERY) {
      try {
        SelectNode s = QueryConverter.convert(query);
        s.unparse(new ParseTreeWriter(new PrintWriter(writer)));
      } catch (SaikuIncompatibleException se) {
        LOG.debug("Cannot convert to new query model mdx, falling back to old version", se);
        this.query.getSelect().unparse(new ParseTreeWriter(new PrintWriter(writer)));
      } catch (Exception e) {
        throw new SaikuServiceException("Cannot convert to new query model", e);
View Full Code Here

TOP

Related Classes of org.olap4j.mdx.SelectNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.