Search in sources :

Example 11 with Execution

use of mondrian.server.Execution in project mondrian by pentaho.

the class SegmentLoader method processData.

RowList processData(SqlStatement stmt, final boolean[] axisContainsNull, final SortedSet<Comparable>[] axisValueSets, final GroupingSetsList groupingSetsList) throws SQLException {
    List<Segment> segments = groupingSetsList.getDefaultSegments();
    int measureCount = segments.size();
    ResultSet rawRows = loadData(stmt, groupingSetsList);
    assert stmt != null;
    final List<SqlStatement.Type> types = stmt.guessTypes();
    int arity = axisValueSets.length;
    final int groupingColumnStartIndex = arity + measureCount;
    // If we're using grouping sets, the SQL query will have a number of
    // indicator columns, and we roll these into a single BitSet column in
    // the processed data set.
    final List<SqlStatement.Type> processedTypes;
    if (groupingSetsList.useGroupingSets()) {
        processedTypes = new ArrayList<SqlStatement.Type>(types.subList(0, groupingColumnStartIndex));
        processedTypes.add(SqlStatement.Type.OBJECT);
    } else {
        processedTypes = types;
    }
    final RowList processedRows = new RowList(processedTypes, 100);
    Execution execution = Locus.peek().execution;
    while (rawRows.next()) {
        // Check if the MDX query was canceled.
        CancellationChecker.checkCancelOrTimeout(++stmt.rowCount, execution);
        checkResultLimit(stmt.rowCount);
        processedRows.createRow();
        // get the columns
        int columnIndex = 0;
        for (int axisIndex = 0; axisIndex < arity; axisIndex++, columnIndex++) {
            final SqlStatement.Type type = types.get(columnIndex);
            switch(type) {
                case OBJECT:
                case STRING:
                    Object o = rawRows.getObject(columnIndex + 1);
                    if (o == null) {
                        o = RolapUtil.sqlNullValue;
                        if (!groupingSetsList.useGroupingSets() || !isAggregateNull(rawRows, groupingColumnStartIndex, groupingSetsList, axisIndex)) {
                            axisContainsNull[axisIndex] = true;
                        }
                    } else {
                        // So it can be processing (comparing and displaying) correctly as String
                        if (o instanceof byte[]) {
                            o = new String((byte[]) o);
                        }
                        axisValueSets[axisIndex].add((Comparable) o);
                    }
                    processedRows.setObject(columnIndex, o);
                    break;
                case INT:
                    final int intValue = rawRows.getInt(columnIndex + 1);
                    if (intValue == 0 && rawRows.wasNull()) {
                        if (!groupingSetsList.useGroupingSets() || !isAggregateNull(rawRows, groupingColumnStartIndex, groupingSetsList, axisIndex)) {
                            axisContainsNull[axisIndex] = true;
                        }
                        processedRows.setNull(columnIndex, true);
                    } else {
                        axisValueSets[axisIndex].add(intValue);
                        processedRows.setInt(columnIndex, intValue);
                    }
                    break;
                case LONG:
                    final long longValue = rawRows.getLong(columnIndex + 1);
                    if (longValue == 0 && rawRows.wasNull()) {
                        if (!groupingSetsList.useGroupingSets() || !isAggregateNull(rawRows, groupingColumnStartIndex, groupingSetsList, axisIndex)) {
                            axisContainsNull[axisIndex] = true;
                        }
                        processedRows.setNull(columnIndex, true);
                    } else {
                        axisValueSets[axisIndex].add(longValue);
                        processedRows.setLong(columnIndex, longValue);
                    }
                    break;
                case DOUBLE:
                    final double doubleValue = rawRows.getDouble(columnIndex + 1);
                    if (doubleValue == 0 && rawRows.wasNull()) {
                        if (!groupingSetsList.useGroupingSets() || !isAggregateNull(rawRows, groupingColumnStartIndex, groupingSetsList, axisIndex)) {
                            axisContainsNull[axisIndex] = true;
                        }
                        processedRows.setNull(columnIndex, true);
                    } else {
                        axisValueSets[axisIndex].add(doubleValue);
                        processedRows.setDouble(columnIndex, doubleValue);
                    }
                    break;
                default:
                    throw Util.unexpected(type);
            }
        }
        // pre-compute which measures are numeric
        final boolean[] numeric = new boolean[measureCount];
        int k = 0;
        for (Segment segment : segments) {
            numeric[k++] = segment.measure.getDatatype().isNumeric();
        }
        // get the measure
        for (int i = 0; i < measureCount; i++, columnIndex++) {
            final SqlStatement.Type type = types.get(columnIndex);
            switch(type) {
                case OBJECT:
                case STRING:
                    Object o = rawRows.getObject(columnIndex + 1);
                    if (o == null) {
                        // convert to placeholder
                        o = Util.nullValue;
                    } else if (numeric[i]) {
                        if (o instanceof Double) {
                        // nothing to do
                        } else if (o instanceof BigDecimal) {
                        // nothing to do // PDI-16761 if we cast it to double type we lose precision
                        } else if (o instanceof Number) {
                            o = ((Number) o).doubleValue();
                        } else if (o instanceof byte[]) {
                            // On MySQL 5.0 in German locale, values can come
                            // out as byte arrays. Don't know why. Bug 1594119.
                            o = Double.parseDouble(new String((byte[]) o));
                        } else {
                            o = Double.parseDouble(o.toString());
                        }
                    }
                    processedRows.setObject(columnIndex, o);
                    break;
                case INT:
                    final int intValue = rawRows.getInt(columnIndex + 1);
                    processedRows.setInt(columnIndex, intValue);
                    if (intValue == 0 && rawRows.wasNull()) {
                        processedRows.setNull(columnIndex, true);
                    }
                    break;
                case LONG:
                    final long longValue = rawRows.getLong(columnIndex + 1);
                    processedRows.setLong(columnIndex, longValue);
                    if (longValue == 0 && rawRows.wasNull()) {
                        processedRows.setNull(columnIndex, true);
                    }
                    break;
                case DOUBLE:
                    final double doubleValue = rawRows.getDouble(columnIndex + 1);
                    processedRows.setDouble(columnIndex, doubleValue);
                    if (doubleValue == 0 && rawRows.wasNull()) {
                        processedRows.setNull(columnIndex, true);
                    }
                    break;
                default:
                    throw Util.unexpected(type);
            }
        }
        if (groupingSetsList.useGroupingSets()) {
            processedRows.setObject(columnIndex, getRollupBitKey(groupingSetsList.getRollupColumns().size(), rawRows, columnIndex));
        }
    }
    return processedRows;
}
Also used : BigDecimal(java.math.BigDecimal) Execution(mondrian.server.Execution) ResultSet(java.sql.ResultSet)

Example 12 with Execution

use of mondrian.server.Execution in project mondrian by pentaho.

the class CancellationTest method testNonEmptyListCancellation.

public void testNonEmptyListCancellation() throws MondrianException {
    // tests that cancellation/timeout is checked in
    // CrossJoinFunDef.nonEmptyList
    propSaver.set(propSaver.properties.CheckCancelOrTimeoutInterval, 1);
    CrossJoinFunDefTester crossJoinFunDef = new CrossJoinFunDefTester(new CrossJoinTest.NullFunDef());
    Result result = executeQuery("select store.[store name].members on 0 from sales");
    Evaluator eval = ((RolapResult) result).getEvaluator(new int[] { 0 });
    TupleList list = new UnaryTupleList();
    for (Position pos : result.getAxes()[0].getPositions()) {
        list.add(pos);
    }
    Execution exec = spy(new Execution(eval.getQuery().getStatement(), 0));
    eval.getQuery().getStatement().start(exec);
    crossJoinFunDef.nonEmptyList(eval, list, null);
    // checkCancelOrTimeout should be called once
    // for each tuple since phase interval is 1
    verify(exec, times(list.size())).checkCancelOrTimeout();
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) TupleList(mondrian.calc.TupleList) UnaryTupleList(mondrian.calc.impl.UnaryTupleList) Execution(mondrian.server.Execution) CrossJoinTest(mondrian.olap.fun.CrossJoinTest)

Example 13 with Execution

use of mondrian.server.Execution in project mondrian by pentaho.

the class CrossJoinTest method testCrossJoinIterCalc_IterationCancellationOnForward.

// The test to verify that cancellation/timeout is checked
// in CrossJoinFunDef$CrossJoinIterCalc$1$1.forward()
public void testCrossJoinIterCalc_IterationCancellationOnForward() {
    propSaver.set(propSaver.properties.CheckCancelOrTimeoutInterval, 1);
    // Get product members as TupleList
    RolapCube salesCube = (RolapCube) cubeByName(getTestContext().getConnection(), SALES_CUBE);
    SchemaReader salesCubeSchemaReader = salesCube.getSchemaReader(getTestContext().getConnection().getRole()).withLocus();
    TupleList productMembers = productMembersPotScrubbersPotsAndPans(salesCubeSchemaReader);
    // Get genders members as TupleList
    Result genders = executeQuery(SELECT_GENDER_MEMBERS);
    TupleList genderMembers = getGenderMembers(genders);
    // Test execution to track cancellation/timeout calls
    Execution execution = spy(new Execution(genders.getQuery().getStatement(), 0));
    // check no execution of checkCancelOrTimeout has been yet
    verify(execution, times(0)).checkCancelOrTimeout();
    Integer crossJoinIterCalc = crossJoinIterCalcIterate(productMembers, genderMembers, execution);
    // checkCancelOrTimeout should be called once for the left tuple
    // from CrossJoinIterCalc$1$1.forward() since phase
    // interval is 1
    verify(execution, times(productMembers.size())).checkCancelOrTimeout();
    assertEquals(productMembers.size() * genderMembers.size(), crossJoinIterCalc.intValue());
}
Also used : UnaryTupleList(mondrian.calc.impl.UnaryTupleList) ArrayTupleList(mondrian.calc.impl.ArrayTupleList) Execution(mondrian.server.Execution) RolapCube(mondrian.rolap.RolapCube)

Example 14 with Execution

use of mondrian.server.Execution in project mondrian by pentaho.

the class SqlConstraintUtilsTest method testReplaceCompoundSlicerPlaceholder.

public void testReplaceCompoundSlicerPlaceholder() {
    final TestContext testContext = TestContext.instance();
    final Connection connection = testContext.getConnection();
    final String queryText = "SELECT {[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE [Time].[1997]";
    final Query query = connection.parseQuery(queryText);
    final QueryAxis querySlicerAxis = query.getSlicerAxis();
    final Member slicerMember = ((MemberExpr) querySlicerAxis.getSet()).getMember();
    final RolapHierarchy slicerHierarchy = ((RolapCube) query.getCube()).getTimeHierarchy(null);
    final Execution execution = new Execution(query.getStatement(), 0L);
    final RolapEvaluatorRoot rolapEvaluatorRoot = new RolapEvaluatorRoot(execution);
    final RolapEvaluator rolapEvaluator = new RolapEvaluator(rolapEvaluatorRoot);
    final Member expectedMember = slicerMember;
    rolapEvaluator.setSlicerContext(expectedMember);
    RolapResult.CompoundSlicerRolapMember placeHolderMember = Mockito.mock(RolapResult.CompoundSlicerRolapMember.class);
    Mockito.doReturn(slicerHierarchy).when(placeHolderMember).getHierarchy();
    // tested call
    Member r = SqlConstraintUtils.replaceCompoundSlicerPlaceholder(placeHolderMember, rolapEvaluator);
    // test
    Assert.assertSame(expectedMember, r);
}
Also used : Query(mondrian.olap.Query) TestContext(mondrian.test.TestContext) Connection(mondrian.olap.Connection) Execution(mondrian.server.Execution) MemberExpr(mondrian.mdx.MemberExpr) Member(mondrian.olap.Member) TestMember(mondrian.olap.fun.TestMember) QueryAxis(mondrian.olap.QueryAxis)

Example 15 with Execution

use of mondrian.server.Execution in project mondrian by pentaho.

the class SqlStatementTest method setUp.

public void setUp() {
    monitor = mock(Monitor.class);
    srv = mock(MondrianServer.class);
    when(srv.getMonitor()).thenReturn(monitor);
    rolapConnection = mock(RolapConnection.class);
    when(rolapConnection.getServer()).thenReturn(srv);
    statMock = mock(StatementImpl.class);
    when(statMock.getMondrianConnection()).thenReturn(rolapConnection);
    execution = new Execution(statMock, 0);
    execution = spy(execution);
    doThrow(MondrianResource.instance().QueryCanceled.ex()).when(execution).checkCancelOrTimeout();
    locus = new Locus(execution, "component", "message");
    statement = new SqlStatement(null, "sql", null, 0, 0, locus, 0, 0, null);
    statement = spy(statement);
}
Also used : Monitor(mondrian.server.monitor.Monitor) MondrianServer(mondrian.olap.MondrianServer) Execution(mondrian.server.Execution) StatementImpl(mondrian.server.StatementImpl) Locus(mondrian.server.Locus)

Aggregations

Execution (mondrian.server.Execution)23 TupleList (mondrian.calc.TupleList)5 UnaryTupleList (mondrian.calc.impl.UnaryTupleList)4 Locus (mondrian.server.Locus)4 Dialect (mondrian.spi.Dialect)4 StatisticsProvider (mondrian.spi.StatisticsProvider)3 ResultSet (java.sql.ResultSet)2 ArrayTupleList (mondrian.calc.impl.ArrayTupleList)2 MemberExpr (mondrian.mdx.MemberExpr)2 Connection (mondrian.olap.Connection)2 Member (mondrian.olap.Member)2 Query (mondrian.olap.Query)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 TestContext (mondrian.test.TestContext)2 StringProperty (org.eigenbase.util.property.StringProperty)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1