Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,8 @@ public enum State {
*/
FRESH, RUNNING, ERROR, CANCELED, TIMEOUT, DONE,
}

public enum Purpose {
DRILL_THROUGH, CELL_SEGMENT, TUPLES, OTHER
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package org.eclipse.daanse.olap.api.execution;

import org.eclipse.daanse.olap.api.monitor.event.SqlStatementEvent;

/**
* Metadata associated with an execution context for tracing, monitoring, and
* debugging.
Expand Down Expand Up @@ -54,7 +52,7 @@ public interface ExecutionMetadata {
*
* @return the purpose, or null if not set
*/
SqlStatementEvent.Purpose purpose();
Execution.Purpose purpose();

/**
* Returns the number of cell requests associated with this execution. Returns 0
Expand Down Expand Up @@ -82,7 +80,7 @@ static ExecutionMetadata empty() {
* @param cellRequestCount the cell request count
* @return an ExecutionMetadata instance
*/
static ExecutionMetadata of(String component, String message, SqlStatementEvent.Purpose purpose,
static ExecutionMetadata of(String component, String message, Execution.Purpose purpose,
int cellRequestCount) {
return new ExecutionMetadataRecord(component, message, purpose, cellRequestCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*/
package org.eclipse.daanse.olap.api.execution;

import org.eclipse.daanse.olap.api.monitor.event.SqlStatementEvent;

/**
* Record implementation of ExecutionMetadata.
*
Expand All @@ -23,6 +21,6 @@
* @param purpose the SQL statement purpose (may be null)
* @param cellRequestCount the cell request count
*/
record ExecutionMetadataRecord(String component, String message, SqlStatementEvent.Purpose purpose,
record ExecutionMetadataRecord(String component, String message, Execution.Purpose purpose,
int cellRequestCount) implements ExecutionMetadata {
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@

public sealed interface SqlStatementEvent extends OlapEvent
permits SqlStatementStartEvent, SqlStatementEndEvent, SqlStatementExecuteEvent {
public enum Purpose {
DRILL_THROUGH, CELL_SEGMENT, TUPLES, OTHER
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package org.eclipse.daanse.olap.api.monitor.event;

import org.eclipse.daanse.olap.api.monitor.event.SqlStatementEvent.Purpose;
import org.eclipse.daanse.olap.api.execution.Execution.Purpose;

public record SqlStatementEventCommon(EventCommon eventCommon, long mdxStatementId, long sqlStatementId, String sql,
Purpose purpose) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ public static int compareValues( Object value0, Object value1 ) {
return ( (Date) value0 ).compareTo( (Date) value1 );
} else if ( value0 instanceof LocalDateTime ) {
return ( (LocalDateTime) value0 ).compareTo( (LocalDateTime) value1 );
} else if ( value0 instanceof OrderKey orderKey0 && value0 instanceof OrderKey orderKey1 ) {
} else if ( value0 instanceof OrderKey orderKey0 && value1 instanceof OrderKey orderKey1 ) {
return orderKey0.compareTo( orderKey1);
} else {
throw newInternal( "cannot compare " + value0 );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.daanse.olap.fun.sort;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.eclipse.daanse.olap.api.element.Member;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
* Tests for {@link Sorter#compareValues(Object, Object)} method.
*/
class SorterCompareValuesTest {

/**
* Test that compareValues correctly compares two different OrderKey objects.
* This test exposes the bug where value0 was checked twice instead of value0 and value1,
* causing all OrderKey comparisons to incorrectly return 0.
*/
@Test
void testCompareValuesWithDifferentOrderKeys() {
// Create two members with different order keys
Member memberA = mock(Member.class, Mockito.withSettings().stubOnly());
Member memberB = mock(Member.class, Mockito.withSettings().stubOnly());

when(memberA.isCalculatedInQuery()).thenReturn(false);
when(memberB.isCalculatedInQuery()).thenReturn(false);
when(memberA.getOrderKey()).thenReturn("A");
when(memberB.getOrderKey()).thenReturn("B");

OrderKey orderKey1 = new OrderKey(memberA);
OrderKey orderKey2 = new OrderKey(memberB);

// The comparison should NOT be 0 since they have different order keys
int result = Sorter.compareValues(orderKey1, orderKey2);

// "A".compareTo("B") should return negative value
assertThat(result)
.as("Comparing OrderKey with 'A' to OrderKey with 'B' should return negative")
.isLessThan(0);

// Also test the reverse
int reverseResult = Sorter.compareValues(orderKey2, orderKey1);
assertThat(reverseResult)
.as("Comparing OrderKey with 'B' to OrderKey with 'A' should return positive")
.isGreaterThan(0);
}

/**
* Test that compareValues returns 0 for equal OrderKey objects.
*/
@Test
void testCompareValuesWithEqualOrderKeys() {
Member memberA = mock(Member.class, Mockito.withSettings().stubOnly());
Member memberB = mock(Member.class, Mockito.withSettings().stubOnly());

when(memberA.isCalculatedInQuery()).thenReturn(false);
when(memberB.isCalculatedInQuery()).thenReturn(false);
when(memberA.getOrderKey()).thenReturn("Same");
when(memberB.getOrderKey()).thenReturn("Same");

OrderKey orderKey1 = new OrderKey(memberA);
OrderKey orderKey2 = new OrderKey(memberB);

int result = Sorter.compareValues(orderKey1, orderKey2);

assertThat(result)
.as("Comparing OrderKeys with same value 'Same' should return 0")
.isEqualTo(0);
}
}
Loading