Skip to content

Commit

Permalink
Rebasing on to master
Browse files Browse the repository at this point in the history
  • Loading branch information
garyluoex committed Mar 16, 2017
1 parent 718e122 commit 74b324b
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.yahoo.bard.webservice.table.PhysicalTable;
import com.yahoo.bard.webservice.table.TableGroup;
import com.yahoo.bard.webservice.table.TableIdentifier;
import com.yahoo.bard.webservice.table.resolver.QueryPlanningConstraint;
import com.yahoo.bard.webservice.table.resolver.NoMatchFoundException;
import com.yahoo.bard.webservice.table.resolver.PhysicalTableResolver;
import com.yahoo.bard.webservice.table.resolver.QueryPlanningConstraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@
*/
public class ResultSetSchema extends BaseSchema {

/**
* The granularity of the ResultSet.
*/
private final Granularity granularity;

/**
* Constructor.
*
* @param granularity The bucketing time grain for this schema
* @param columns The columns in this schema
*/
public ResultSetSchema(@NotNull Granularity granularity, Iterable<Column> columns) {
super(granularity, columns);
super(columns);
this.granularity = granularity;
}

/**
Expand All @@ -39,4 +45,31 @@ public ResultSetSchema withAddColumn(Column column) {
columns.add(column);
return new ResultSetSchema(this.getGranularity(), columns);
}

/**
* Granularity.
*
* @return the granularity for this schema
*/
public Granularity getGranularity() {
return granularity;
}

@Override
public boolean equals(final Object o) {
if (this == o) { return true; }
if (!(o instanceof ResultSetSchema)) { return false; }
if (!super.equals(o)) { return false; }

final ResultSetSchema that = (ResultSetSchema) o;

return granularity != null ? granularity.equals(that.granularity) : that.granularity == null;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (granularity != null ? granularity.hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import io.druid.timeline.DataSegment;

import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ public String getPhysicalColumnName(String logicalName) {
protected void setAvailability(Availability availability) {
this.availability = availability;
}
}

@Override
@Deprecated
public Set<Column> getColumns() {
return getSchema().getColumns();
}

@Override
@Deprecated
public ZonedTimeGrain getTimeGrain() {
return schema.getGranularity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms.
package com.yahoo.bard.webservice.table;

import com.yahoo.bard.webservice.druid.model.query.Granularity;

import com.google.common.collect.Sets;

import java.util.LinkedHashSet;
Expand All @@ -15,16 +13,13 @@
public class BaseSchema implements Schema {

private final LinkedHashSet<Column> columns;
private final Granularity granularity;

/**
* Constructor.
*
* @param granularity The granularity for this schema.
* @param columns The columns for this schema.
*/
protected BaseSchema(Granularity granularity, Iterable<Column> columns) {
this.granularity = granularity;
protected BaseSchema(Iterable<Column> columns) {
this.columns = Sets.newLinkedHashSet(columns);
}

Expand All @@ -33,11 +28,6 @@ public LinkedHashSet<Column> getColumns() {
return columns;
}

@Override
public Granularity getGranularity() {
return granularity;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -48,14 +38,11 @@ public boolean equals(Object o) {
}

BaseSchema that = (BaseSchema) o;
return this.getClass() == o.getClass()
&& Objects.equals(columns, that.columns)
&& Objects.equals(granularity, that.getGranularity()
);
return Objects.equals(columns, that.columns);
}

@Override
public int hashCode() {
return Objects.hash(granularity, columns);
return Objects.hash(columns);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ public class LogicalTableSchema extends BaseSchema {
* @param metricDictionary The dictionary to resolve metric names from the table group against
*/
public LogicalTableSchema(TableGroup tableGroup, Granularity granularity, MetricDictionary metricDictionary) {
super(granularity, buildLogicalColumns(tableGroup, granularity, metricDictionary));
super(toColumns(tableGroup, granularity, metricDictionary));
this.granularity = granularity;
}

public Granularity getGranularity() {
return granularity;
}

/**
Expand All @@ -39,14 +44,14 @@ public LogicalTableSchema(TableGroup tableGroup, Granularity granularity, Metric
*
* @return The union of all columns from the table group
*/
private static LinkedHashSet<Column> buildLogicalColumns(
private static LinkedHashSet<Column> toColumns(
TableGroup tableGroup,
Granularity granularity,
MetricDictionary metricDictionary
) {
return Stream.concat(
tableGroup.getDimensions().stream()
.map(DimensionColumn::new),
.map(DimensionColumn::new),
tableGroup.getApiMetricNames().stream()
.filter(apiMetricName -> apiMetricName.isValidFor(granularity))
.map(ApiMetricName::getApiName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.util.Set;

/**
* An interface describing the Fili model for a fact data source (e.g. a table of dimensions and metrics).
* It may be backed by a single concrete fact data source or by more than one with underlying joins.
* An interface describing a config level physical table.
* It may be backed by a single concrete data source or not.
*/
public interface PhysicalTable extends Table {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ public class PhysicalTableSchema extends BaseSchema {
private final Map<String, String> logicalToPhysicalColumnNames;
private final Map<String, Set<String>> physicalToLogicalColumnNames;

/**
* Constructor.
*
* @param timeGrain The time grain of this physical table
* @param columns The columns for this table
*/
public PhysicalTableSchema(
@NotNull ZonedTimeGrain timeGrain,
Iterable<Column> columns
) {
this(timeGrain, columns, Collections.emptyMap());
}

/**
* Constructor.
*
Expand All @@ -32,7 +45,7 @@ public PhysicalTableSchema(
Iterable<Column> columns,
@NotNull Map<String, String> logicalToPhysicalColumnNames
) {
super(timeGrain, columns);
super(columns);
this.timeGrain = timeGrain;

this.logicalToPhysicalColumnNames = Collections.unmodifiableMap(logicalToPhysicalColumnNames);
Expand Down Expand Up @@ -93,7 +106,7 @@ public boolean containsLogicalName(String logicalName) {
*
* @return the granularity for this schema
*/
public ZonedTimeGrain getTimeGrain() {
public ZonedTimeGrain getGranularity() {
return timeGrain;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class ZonedSchema extends BaseSchema implements Schema {

private final DateTimeZone dateTimeZone;
private final Granularity granularity;

/**
* Constructor.
Expand All @@ -31,7 +32,8 @@ public ZonedSchema(
@NotNull DateTimeZone dateTimeZone,
@NotNull Iterable<Column> columns
) {
super(granularity, columns);
super(columns);
this.granularity = granularity;
this.dateTimeZone = dateTimeZone;
}

Expand All @@ -46,4 +48,13 @@ public ZonedSchema(ZonedSchema schema) {
public DateTimeZone getDateTimeZone() {
return dateTimeZone;
}

/**
* Granularity.
*
* @return the granularity for this schema
*/
public Granularity getGranularity() {
return granularity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.joda.time.Interval;

import java.util.Map;
import java.util.SortedSet;
import java.util.Set;

/**
* Availability describes the intervals available by column for a table.
Expand All @@ -22,7 +22,7 @@ public interface Availability {
*
* @return A set of names for datasources backing this table
*/
SortedSet<TableName> getDataSourceNames();
Set<TableName> getDataSourceNames();

/**
* The availability of all columns.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public SchemaPhysicalTableMatcher(QueryPlanningConstraint requestConstraints) {

@Override
public boolean test(PhysicalTable table) {
if (!requestConstraints.getMinimumGranularity().satisfiedBy(table.getSchema().getTimeGrain())) {
if (!requestConstraints.getMinimumGranularity().satisfiedBy(table.getSchema().getGranularity())) {
return false;
}

Expand All @@ -55,12 +55,22 @@ public NoMatchFoundException noneFoundException() {
String logicalTableName = requestConstraints.getLogicalTable().getName();
Set<String> logicalMetrics = requestConstraints.getLogicalMetricNames();
Set<String> dimensions = requestConstraints.getAllDimensionNames();
String grainName = requestConstraints.getMinimumGranularity().getName();

LOG.error(
MESSAGE_FORMAT.logFormat(logicalTableName, dimensions, logicalMetrics, grainName)
MESSAGE_FORMAT.logFormat(
logicalTableName,
dimensions,
logicalMetrics,
requestConstraints.getMinimumGranularity().getName()
)
);
return new NoMatchFoundException(
MESSAGE_FORMAT.format(logicalTableName, dimensions, logicalMetrics, grainName)
MESSAGE_FORMAT.format(
logicalTableName,
dimensions,
logicalMetrics,
requestConstraints.getMinimumGranularity().getName()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected Map<String, Object> generateSlice(
throw new BadApiRequestException(msg);
}

Map<Column, List<Interval>> columnCache = table.getAvailability().getAvailableIntervals();
Map<Column, Set<Interval>> columnCache = table.getAllAvailableIntervals();
Set<Map<String, Object>> dimensionsResult = new LinkedHashSet<>();
Set<Map<String, Object>> metricsResult = new LinkedHashSet<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.yahoo.bard.webservice.metadata.SegmentInfo
import com.yahoo.bard.webservice.table.Column
import com.yahoo.bard.webservice.table.PhysicalTableDictionary
import com.yahoo.bard.webservice.table.Table
import com.yahoo.bard.webservice.table.resolver.DataSourceConstraint
import com.yahoo.bard.webservice.web.endpoints.SlicesServlet

import org.joda.time.DateTime
Expand Down Expand Up @@ -92,7 +93,7 @@ class SlicesApiRequestSpec extends BaseDataSourceMetadataSpec {
Set<Map<String, Object>> dimensionsResult = new LinkedHashSet<>()
Set<Map<String, Object>> metricsResult = new LinkedHashSet<>()
table.getAvailability().getAvailableIntervals().each {
table.getAvailability().getAllAvailableIntervals().each {
Map<String, Object> row = new LinkedHashMap<>()
row.put("intervals", it.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PartialDataRequestHandlerSpec extends Specification {
def setup() {
apiRequest.getDimensions() >> Collections.emptySet()
apiRequest.getFilterDimensions() >> Collections.emptySet()
apiRequest.getFilters() >> Collections.emptyMap()
groupByQuery.getMetricDimensions() >> Collections.emptySet()
groupByQuery.getDependentFieldNames() >> Collections.emptySet()
groupByQuery.getInnermostQuery() >> groupByQuery
Expand Down
Loading

0 comments on commit 74b324b

Please sign in to comment.