Skip to content

Commit

Permalink
Implement Cumulative Metric (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldmedal committed Oct 30, 2023
1 parent 75bc4b2 commit a1decb1
Show file tree
Hide file tree
Showing 24 changed files with 901 additions and 31 deletions.
22 changes: 22 additions & 0 deletions accio-base/src/main/java/io/accio/base/AccioMDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.accio.base.dto.Column;
import io.accio.base.dto.CumulativeMetric;
import io.accio.base.dto.DateSpine;
import io.accio.base.dto.EnumDefinition;
import io.accio.base.dto.Manifest;
import io.accio.base.dto.Metric;
Expand Down Expand Up @@ -143,6 +145,21 @@ public Optional<Metric> getMetric(CatalogSchemaTableName name)
return Optional.empty();
}

public Optional<CumulativeMetric> getCumulativeMetric(String name)
{
return manifest.getCumulativeMetrics().stream()
.filter(metric -> metric.getName().equals(name))
.findAny();
}

public Optional<CumulativeMetric> getCumulativeMetric(CatalogSchemaTableName name)
{
if (catalog.equals(name.getCatalogName()) && schema.equals(name.getSchemaTableName().getSchemaName())) {
return getCumulativeMetric(name.getSchemaTableName().getTableName());
}
return Optional.empty();
}

public Optional<View> getView(String name)
{
return manifest.getViews().stream()
Expand Down Expand Up @@ -172,4 +189,9 @@ private static Optional<Column> getColumn(Model model, String name)
.filter(column -> column.getName().equals(name))
.findAny();
}

public DateSpine getDateSpine()
{
return manifest.getDateSpine();
}
}
144 changes: 144 additions & 0 deletions accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.accio.base.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.airlift.units.Duration;

import java.util.Objects;

public class CumulativeMetric
implements PreAggregationInfo
{
public static CumulativeMetric cumulativeMetric(
String name,
String baseModel,
Measure measure,
Window window)
{
return new CumulativeMetric(name, baseModel, measure, window, false, null, null);
}

private final String name;
private final String baseModel;
private final Measure measure;
private final Window window;
private final boolean preAggregated;
private final Duration refreshTime;
private final String description;

@JsonCreator
public CumulativeMetric(
@JsonProperty("name") String name,
@JsonProperty("baseModel") String baseModel,
@JsonProperty("measure") Measure measure,
@JsonProperty("window") Window window,
@JsonProperty("preAggregated") boolean preAggregated,
@JsonProperty("refreshTime") Duration refreshTime,
@JsonProperty("description") String description)
{
this.name = name;
this.baseModel = baseModel;
this.measure = measure;
this.window = window;
this.preAggregated = preAggregated;
this.refreshTime = refreshTime;
this.description = description;
}

@JsonProperty
public String getName()
{
return name;
}

@JsonProperty
public String getBaseModel()
{
return baseModel;
}

@JsonProperty
public Measure getMeasure()
{
return measure;
}

@JsonProperty
public Window getWindow()
{
return window;
}

@JsonProperty
public boolean isPreAggregated()
{
return preAggregated;
}

@JsonProperty
public Duration getRefreshTime()
{
return refreshTime;
}

@JsonProperty
public String getDescription()
{
return description;
}

@Override
public int hashCode()
{
return Objects.hash(name, baseModel, measure, window, preAggregated, refreshTime, description);
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

CumulativeMetric that = (CumulativeMetric) o;
return preAggregated == that.preAggregated &&
Objects.equals(name, that.name) &&
Objects.equals(baseModel, that.baseModel) &&
Objects.equals(measure, that.measure) &&
Objects.equals(window, that.window) &&
Objects.equals(refreshTime, that.refreshTime) &&
Objects.equals(description, that.description);
}

@Override
public String toString()
{
return "CumulativeMetric{" +
"name='" + name + '\'' +
", baseModel='" + baseModel + '\'' +
", measure=" + measure +
", window=" + window +
", preAggregated=" + preAggregated +
", refreshTime=" + refreshTime +
", description='" + description + '\'' +
'}';
}
}
89 changes: 89 additions & 0 deletions accio-base/src/main/java/io/accio/base/dto/DateSpine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.accio.base.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

public class DateSpine
{
public static final DateSpine DEFAULT = new DateSpine(TimeUnit.DAY, "1970-01-01", "2077-12-31");

private final TimeUnit unit;
private final String start;
private final String end;

@JsonCreator
public DateSpine(
@JsonProperty("unit") TimeUnit unit,
@JsonProperty("start") String start,
@JsonProperty("end") String end)
{
this.unit = unit;
this.start = start;
this.end = end;
}

@JsonProperty
public TimeUnit getUnit()
{
return unit;
}

@JsonProperty
public String getStart()
{
return start;
}

@JsonProperty
public String getEnd()
{
return end;
}

@Override
public String toString()
{
return "DateSpine{" +
"unit=" + unit +
", start='" + start + '\'' +
", end='" + end + '\'' +
'}';
}

@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DateSpine dateSpine = (DateSpine) o;
return unit == dateSpine.unit &&
Objects.equals(start, dateSpine.start) &&
Objects.equals(end, dateSpine.end);
}

@Override
public int hashCode()
{
return Objects.hash(unit, start, end);
}
}
Loading

0 comments on commit a1decb1

Please sign in to comment.