forked from apache/lucene
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bharathwaj G <[email protected]>
- Loading branch information
1 parent
9574cbd
commit c0de037
Showing
49 changed files
with
5,899 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...java/org/apache/lucene/codecs/freshstartree/aggregator/AggregationFunctionColumnPair.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.lucene.codecs.freshstartree.aggregator; | ||
|
||
import java.util.Comparator; | ||
|
||
/** Aggregation function, doc values column pair */ | ||
public class AggregationFunctionColumnPair implements Comparable<AggregationFunctionColumnPair> { | ||
public static final String DELIMITER = "__"; | ||
public static final String STAR = "*"; | ||
public static final AggregationFunctionColumnPair COUNT_STAR = | ||
new AggregationFunctionColumnPair(AggregationFunctionType.COUNT, STAR); | ||
|
||
private final AggregationFunctionType _functionType; | ||
private final String _column; | ||
|
||
public AggregationFunctionColumnPair(AggregationFunctionType functionType, String column) { | ||
_functionType = functionType; | ||
if (functionType == AggregationFunctionType.COUNT) { | ||
_column = STAR; | ||
} else { | ||
_column = column; | ||
} | ||
} | ||
|
||
public AggregationFunctionType getFunctionType() { | ||
return _functionType; | ||
} | ||
|
||
public String getColumn() { | ||
return _column; | ||
} | ||
|
||
public String toColumnName() { | ||
return toColumnName(_functionType, _column); | ||
} | ||
|
||
public static String toColumnName(AggregationFunctionType functionType, String column) { | ||
return functionType.getName() + DELIMITER + column; | ||
} | ||
|
||
public static AggregationFunctionColumnPair fromColumnName(String columnName) { | ||
String[] parts = columnName.split(DELIMITER, 2); | ||
return fromFunctionAndColumnName(parts[0], parts[1]); | ||
} | ||
|
||
private static AggregationFunctionColumnPair fromFunctionAndColumnName( | ||
String functionName, String columnName) { | ||
AggregationFunctionType functionType = | ||
AggregationFunctionType.getAggregationFunctionType(functionName); | ||
if (functionType == AggregationFunctionType.COUNT) { | ||
return COUNT_STAR; | ||
} else { | ||
return new AggregationFunctionColumnPair(functionType, columnName); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return 31 * _functionType.hashCode() + _column.hashCode(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj instanceof AggregationFunctionColumnPair) { | ||
AggregationFunctionColumnPair anotherPair = (AggregationFunctionColumnPair) obj; | ||
return _functionType == anotherPair._functionType && _column.equals(anotherPair._column); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return toColumnName(); | ||
} | ||
|
||
@Override | ||
public int compareTo(AggregationFunctionColumnPair other) { | ||
return Comparator.comparing((AggregationFunctionColumnPair o) -> o._column) | ||
.thenComparing((AggregationFunctionColumnPair o) -> o._functionType) | ||
.compare(this, other); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...s/src/java/org/apache/lucene/codecs/freshstartree/aggregator/AggregationFunctionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.lucene.codecs.freshstartree.aggregator; | ||
|
||
/** Aggregated function type */ | ||
public enum AggregationFunctionType { | ||
COUNT("count"), | ||
SUM("sum"); | ||
// AVG("avg"); | ||
|
||
private String name; | ||
|
||
AggregationFunctionType(String name) { | ||
this.name = name; | ||
} | ||
|
||
public static AggregationFunctionType getAggregationFunctionType(String functionName) { | ||
return AggregationFunctionType.valueOf(functionName); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...decs/src/java/org/apache/lucene/codecs/freshstartree/aggregator/CountValueAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.lucene.codecs.freshstartree.aggregator; | ||
|
||
/** Count value aggregator */ | ||
public class CountValueAggregator implements ValueAggregator { | ||
public static final DataType AGGREGATED_VALUE_TYPE = DataType.LONG; | ||
|
||
@Override | ||
public AggregationFunctionType getAggregationType() { | ||
return AggregationFunctionType.COUNT; | ||
} | ||
|
||
@Override | ||
public DataType getAggregatedValueType() { | ||
return AGGREGATED_VALUE_TYPE; | ||
} | ||
|
||
@Override | ||
public Long getInitialAggregatedValue(Long rawValue) { | ||
return 1l; | ||
} | ||
|
||
@Override | ||
public Long applyRawValue(Long value, Long rawValue) { | ||
return value + 1; | ||
} | ||
|
||
@Override | ||
public Long applyAggregatedValue(Long value, Long aggregatedValue) { | ||
return value + aggregatedValue; | ||
} | ||
|
||
@Override | ||
public Long cloneAggregatedValue(Long value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int getMaxAggregatedValueByteSize() { | ||
return Long.BYTES; | ||
} | ||
|
||
@Override | ||
public byte[] serializeAggregatedValue(Long value) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Long deserializeAggregatedValue(byte[] bytes) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
lucene/codecs/src/java/org/apache/lucene/codecs/freshstartree/aggregator/DataType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.lucene.codecs.freshstartree.aggregator; | ||
|
||
/** Data type of doc values */ | ||
public enum DataType { | ||
INT(Integer.BYTES, true), | ||
LONG(Long.BYTES, true), | ||
FLOAT(Float.BYTES, true), | ||
DOUBLE(Double.BYTES, true); | ||
|
||
private final int _size; | ||
private final boolean _numeric; | ||
|
||
DataType(int size, boolean numeric) { | ||
_size = size; | ||
_numeric = numeric; | ||
} | ||
|
||
/** Returns the number of bytes needed to store the data type. */ | ||
public int size() { | ||
if (_size >= 0) { | ||
return _size; | ||
} | ||
throw new IllegalStateException("Cannot get number of bytes for: " + this); | ||
} | ||
|
||
/** | ||
* Returns {@code true} if the data type is numeric (INT, LONG, FLOAT, DOUBLE, BIG_DECIMAL), | ||
* {@code false} otherwise. | ||
*/ | ||
public boolean isNumeric() { | ||
return _numeric; | ||
} | ||
|
||
/** Converts the given string value to the data type. Returns byte[] for BYTES. */ | ||
public Object convert(String value) { | ||
try { | ||
switch (this) { | ||
case INT: | ||
return Integer.valueOf(value); | ||
case LONG: | ||
return Long.valueOf(value); | ||
case FLOAT: | ||
return Float.valueOf(value); | ||
case DOUBLE: | ||
return Double.valueOf(value); | ||
default: | ||
throw new IllegalStateException(); | ||
} | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException(e); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...codecs/src/java/org/apache/lucene/codecs/freshstartree/aggregator/SumValueAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.lucene.codecs.freshstartree.aggregator; | ||
|
||
/** Sum value aggregator */ | ||
public class SumValueAggregator implements ValueAggregator { | ||
public static final DataType AGGREGATED_VALUE_TYPE = DataType.LONG; | ||
|
||
@Override | ||
public AggregationFunctionType getAggregationType() { | ||
return AggregationFunctionType.SUM; | ||
} | ||
|
||
@Override | ||
public DataType getAggregatedValueType() { | ||
return AGGREGATED_VALUE_TYPE; | ||
} | ||
|
||
@Override | ||
public Long getInitialAggregatedValue(Long rawValue) { | ||
return rawValue; | ||
} | ||
|
||
@Override | ||
public Long applyRawValue(Long value, Long rawValue) { | ||
return value + rawValue; | ||
} | ||
|
||
@Override | ||
public Long applyAggregatedValue(Long value, Long aggregatedValue) { | ||
return value + aggregatedValue; | ||
} | ||
|
||
@Override | ||
public Long cloneAggregatedValue(Long value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int getMaxAggregatedValueByteSize() { | ||
return Long.BYTES; | ||
} | ||
|
||
@Override | ||
public byte[] serializeAggregatedValue(Long value) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Long deserializeAggregatedValue(byte[] bytes) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
Oops, something went wrong.