Skip to content

Commit

Permalink
Pre compute poc
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <[email protected]>
  • Loading branch information
bharath-techie committed Jan 17, 2024
1 parent 9574cbd commit c0de037
Show file tree
Hide file tree
Showing 49 changed files with 5,899 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lucene/codecs/src/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
exports org.apache.lucene.codecs.blockterms;
exports org.apache.lucene.codecs.blocktreeords;
exports org.apache.lucene.codecs.bloom;
exports org.apache.lucene.codecs.freshstartree.aggregator;
exports org.apache.lucene.codecs.freshstartree.builder;
exports org.apache.lucene.codecs.freshstartree.codec;
exports org.apache.lucene.codecs.freshstartree.node;
exports org.apache.lucene.codecs.freshstartree.query;
exports org.apache.lucene.codecs.freshstartree.util;
exports org.apache.lucene.codecs.memory;
exports org.apache.lucene.codecs.simpletext;
exports org.apache.lucene.codecs.uniformsplit;
Expand Down
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);
}
}
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;
}
}
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();
}
}
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);
}
}
}
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();
}
}
Loading

0 comments on commit c0de037

Please sign in to comment.