Skip to content

Commit edb764a

Browse files
committed
create olap modules - common
Signed-off-by: dbulahov <[email protected]>
1 parent 4a329a7 commit edb764a

File tree

1,224 files changed

+91183
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,224 files changed

+91183
-0
lines changed

common/pom.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.eclipse.daanse</groupId>
7+
<artifactId>org.eclipse.daanse.olap</artifactId>
8+
<version>${revision}</version>
9+
</parent>
10+
<artifactId>org.eclipse.daanse.olap.common</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.osgi</groupId>
16+
<artifactId>org.osgi.service.metatype.annotations</artifactId>
17+
<scope>compile</scope>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.osgi</groupId>
21+
<artifactId>org.osgi.namespace.unresolvable</artifactId>
22+
<scope>compile</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>biz.aQute.bnd</groupId>
26+
<artifactId>biz.aQute.bndlib</artifactId>
27+
<version>${bnd.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>com.github.ben-manes.caffeine</groupId>
31+
<artifactId>caffeine</artifactId>
32+
<version>${caffeine.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.osgi</groupId>
36+
<artifactId>org.osgi.service.metatype.annotations</artifactId>
37+
<scope>compile</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.eclipse.daanse</groupId>
41+
<artifactId>org.eclipse.daanse.olap.api</artifactId>
42+
<version>0.0.1-SNAPSHOT</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.eclipse.daanse</groupId>
46+
<artifactId>org.eclipse.daanse.olap.action.api</artifactId>
47+
<version>0.0.1-SNAPSHOT</version>
48+
</dependency>
49+
</dependencies>
50+
</project>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.olap.calc.base;
15+
16+
import java.time.Instant;
17+
import java.util.ArrayList;
18+
import java.util.HashMap;
19+
import java.util.List;
20+
import java.util.Map;
21+
import java.util.Optional;
22+
23+
import org.eclipse.daanse.olap.api.Evaluator;
24+
import org.eclipse.daanse.olap.api.calc.profile.CalcEvaluationProfile;
25+
import org.eclipse.daanse.olap.api.calc.profile.CalculationProfile;
26+
import org.eclipse.daanse.olap.api.calc.profile.ProfilingCalc;
27+
import org.eclipse.daanse.olap.api.type.Type;
28+
import org.eclipse.daanse.olap.calc.base.profile.CalcEvaluationProfileR;
29+
import org.eclipse.daanse.olap.calc.base.profile.CalcProfileR;
30+
31+
public abstract class AbstractProfilingCalc<T> implements ProfilingCalc<T> {
32+
33+
private Type type;
34+
35+
private Instant firstEvalStart = null;
36+
private Instant lastEvalEnd = null;
37+
38+
private final List<CalcEvaluationProfile> evaluations = new ArrayList<CalcEvaluationProfile>();
39+
40+
/**
41+
* Abstract Implementation of {@link ProfilingCalc} that generated a
42+
* {@link CalculationProfile} while calling
43+
* {@link #evaluateWithProfile(Evaluator)))
44+
*
45+
* @param Type
46+
* @param name
47+
*/
48+
public AbstractProfilingCalc(Type type) {
49+
this.type = type;
50+
}
51+
52+
@Override
53+
public T evaluateWithProfile(Evaluator evaluator) {
54+
Instant startEval = Instant.now();
55+
if (firstEvalStart == null) {
56+
firstEvalStart = startEval;
57+
}
58+
final T evalResult = evaluate(evaluator);
59+
60+
Instant endEval = Instant.now();
61+
lastEvalEnd = endEval;
62+
63+
profileEvaluation(startEval, endEval, evalResult);
64+
return evalResult;
65+
}
66+
67+
protected void profileEvaluation(Instant evaluationStart, Instant evaluationEnd, T evaluationResult) {
68+
69+
CalcEvaluationProfile evaluationProfile = new CalcEvaluationProfileR(evaluationStart, evaluationEnd,
70+
evaluationResult, Map.of());
71+
evaluations.add(evaluationProfile);
72+
73+
}
74+
75+
protected Map<String, Object> profilingProperties(Map<String, Object> properties) {
76+
return properties;
77+
}
78+
79+
public CalculationProfile getCalculationProfile() {
80+
final List<CalculationProfile> childProfiles = getChildProfiles();
81+
Map<String, Object> profilingProperties = profilingProperties(new HashMap<String, Object>());
82+
return new CalcProfileR(this.getClass(), getType(), getResultStyle(), Optional.ofNullable(firstEvalStart),
83+
Optional.ofNullable(lastEvalEnd), profilingProperties, evaluations, childProfiles);
84+
}
85+
86+
List<CalculationProfile> getChildProfiles() {
87+
return List.of();
88+
}
89+
90+
@Override
91+
public Type getType() {
92+
return type;
93+
}
94+
95+
protected void requiresType(Class<? extends Type> typeClass) {
96+
Type type = getType();
97+
if (!typeClass.isInstance(type)) {
98+
throw new RuntimeException("Expecting Type " + typeClass + " but was " + type);
99+
}
100+
101+
}
102+
103+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.olap.calc.base;
15+
16+
import java.util.List;
17+
18+
import org.eclipse.daanse.olap.api.Evaluator;
19+
import org.eclipse.daanse.olap.api.calc.ConstantCalc;
20+
import org.eclipse.daanse.olap.api.calc.ResultStyle;
21+
import org.eclipse.daanse.olap.api.calc.profile.CalculationProfile;
22+
import org.eclipse.daanse.olap.api.element.Hierarchy;
23+
import org.eclipse.daanse.olap.api.type.Type;
24+
25+
public abstract class AbstractProfilingConstantCalc<T> extends AbstractProfilingCalc<T> implements ConstantCalc<T> {
26+
27+
private T value;
28+
29+
public AbstractProfilingConstantCalc(T value, Type type) {
30+
super(type);
31+
this.value = value;
32+
}
33+
34+
@Override
35+
public T evaluate(Evaluator evaluator) {
36+
return value;
37+
}
38+
39+
@Override
40+
public boolean dependsOn(Hierarchy hierarchy) {
41+
return false;
42+
}
43+
44+
@Override
45+
public ResultStyle getResultStyle() {
46+
return value == null ? ResultStyle.VALUE : ResultStyle.VALUE_NOT_NULL;
47+
}
48+
49+
@Override
50+
List<CalculationProfile> getChildProfiles() {
51+
return List.of();
52+
}
53+
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
15+
package org.eclipse.daanse.olap.calc.base;
16+
17+
import java.time.Instant;
18+
import java.util.Collection;
19+
import java.util.Map;
20+
21+
import org.eclipse.daanse.olap.api.type.Type;
22+
23+
public abstract class AbstractProfilingIteratorCalc<T> extends AbstractProfilingCalc<T> {
24+
25+
public AbstractProfilingIteratorCalc(Type type) {
26+
super(type);
27+
}
28+
29+
private long elementCount;
30+
private long elementSquaredCount;
31+
32+
@Override
33+
protected void profileEvaluation(Instant evaluationStart, Instant evaluationEnd, T evaluationResult) {
34+
super.profileEvaluation(evaluationStart, evaluationEnd, evaluationResult);
35+
if (evaluationResult instanceof Collection c) {
36+
long size = c.size();
37+
elementCount += size;
38+
elementSquaredCount += size * size;
39+
}
40+
}
41+
42+
@Override
43+
protected Map<String, Object> profilingProperties(Map<String, Object> properties) {
44+
45+
// TODO: may be removed writer can calculate its won because has access to the
46+
// objects
47+
properties.put("elementCount", elementCount);
48+
properties.put("elementSquaredCount", elementSquaredCount);
49+
return properties;
50+
}
51+
52+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.olap.calc.base;
15+
16+
import java.util.List;
17+
import java.util.stream.Stream;
18+
19+
import org.eclipse.daanse.olap.api.calc.Calc;
20+
import org.eclipse.daanse.olap.api.calc.ResultStyle;
21+
import org.eclipse.daanse.olap.api.calc.profile.CalculationProfile;
22+
import org.eclipse.daanse.olap.api.calc.profile.ProfilingCalc;
23+
import org.eclipse.daanse.olap.api.element.Hierarchy;
24+
import org.eclipse.daanse.olap.api.type.Type;
25+
import org.eclipse.daanse.olap.calc.base.util.HirarchyDependsChecker;
26+
27+
public abstract class AbstractProfilingNestedCalc<E> extends AbstractProfilingCalc<E>
28+
implements Calc<E> {
29+
30+
private final Calc<?>[] childCalcs;
31+
32+
/**
33+
* {@inheritDoc}
34+
*
35+
* Holds the childCalcs witch are accessible using {@link #getChildCalcs()}.
36+
* Enhances its own {@link CalculationProfile} with the Children's
37+
* {@link CalculationProfile}.
38+
*
39+
* @param calcs Child {@link Calc}s that are needed to calculate this.
40+
*/
41+
// protected AbstractProfilingNestedCalc(Type type, C[] childCalcs) {
42+
// super(type);
43+
// this.childCalcs = childCalcs;
44+
//
45+
// }
46+
47+
protected AbstractProfilingNestedCalc(Type type, Calc<?>... childCalcs) {
48+
super(type);
49+
this.childCalcs = childCalcs;
50+
}
51+
52+
public Calc<?>[] getChildCalcs() {
53+
return childCalcs;
54+
}
55+
56+
public Calc<?> getChildCalc(int i) {
57+
return childCalcs[i];
58+
}
59+
60+
public <D extends Calc<?>> D getChildCalc(int i, Class<D> clazz) {
61+
return childCalcs[i] != null ? clazz.cast(childCalcs[i]) : null;
62+
}
63+
64+
protected Calc<?> getFirstChildCalc() {
65+
return getChildCalcs()[0];
66+
}
67+
68+
@Override
69+
public boolean dependsOn(Hierarchy hierarchy) {
70+
return HirarchyDependsChecker.checkAnyDependsOnChilds(getChildCalcs(), hierarchy);
71+
}
72+
73+
@Override
74+
public ResultStyle getResultStyle() {
75+
return ResultStyle.VALUE;
76+
}
77+
78+
@Override
79+
protected List<CalculationProfile> getChildProfiles() {
80+
List<CalculationProfile> childProfiles = Stream.of(getChildCalcs()).filter(ProfilingCalc.class::isInstance)
81+
.map(ProfilingCalc.class::cast).map(ProfilingCalc::getCalculationProfile).toList();
82+
83+
return childProfiles;
84+
}
85+
86+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.olap.calc.base;
15+
16+
import org.eclipse.daanse.olap.api.calc.ResultStyle;
17+
import org.eclipse.daanse.olap.api.type.Type;
18+
19+
public abstract class AbstractProfilingScalarCalc<T> extends AbstractProfilingCalc<T> {
20+
21+
public AbstractProfilingScalarCalc(Type type) {
22+
super(type);
23+
}
24+
25+
@Override
26+
public ResultStyle getResultStyle() {
27+
return ResultStyle.VALUE;
28+
}
29+
30+
}

0 commit comments

Comments
 (0)