Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,18 @@ public String getType() {
public void serializeToText(ExpressionSerializer serializer) {
serializer.serialize(this);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof BinaryExpression)) {
return false;
}
BinaryExpression that = (BinaryExpression) obj;
return this.type.equals(that.type) &&
this.lhs.equals(that.lhs) &&
this.rhs.equals(that.rhs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,20 @@ public Object evaluate(IEvaluationContext context) {
public String toString() {
return identifier;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof IdentifierExpression)) {
return false;
}
IdentifierExpression that = (IdentifierExpression) obj;
return this.identifier.equals(that.identifier) &&
((this.qualifier == null && that.qualifier == null) ||
(this.qualifier != null && this.qualifier.equals(that.qualifier))) &&
((this.dataType == null && that.dataType == null) ||
(this.dataType != null && this.dataType.equals(that.dataType)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected LiteralExpression(T value) {
}

/**
* NOTE: do not change the method name since it's used in the ExpressionDeserializer}
* NOTE: do not change the method name since it's used in the ExpressionDeserializer
*/
public T getValue() {
return value;
Expand Down Expand Up @@ -162,6 +162,18 @@ public void serializeToText(ExpressionSerializer serializer) {
serializer.serialize(this);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LiteralExpression)) {
return false;
}
LiteralExpression<?> that = (LiteralExpression<?>) obj;
return this.getDataType() == that.getDataType() && this.value.equals(that.value);
}

public abstract boolean canNegate();

public LiteralExpression<T> negate() {
Expand Down Expand Up @@ -244,7 +256,7 @@ public LiteralExpression<?> castTo(IDataType targetType) {
return this;

case DOUBLE:
return new LiteralExpression.DoubleLiteral(((Number) value).doubleValue());
return new LiteralExpression.DoubleLiteral(value.doubleValue());

case BOOLEAN:
return new LiteralExpression.BooleanLiteral(value != 0);
Expand Down Expand Up @@ -291,13 +303,13 @@ public LiteralExpression<?> castTo(IDataType targetType) {
return new LiteralExpression.StringLiteral(value.toString());

case LONG:
return new LiteralExpression.LongLiteral(((Number) value).longValue());
return new LiteralExpression.LongLiteral(value.longValue());

case DOUBLE:
return this;

case BOOLEAN:
return new LiteralExpression.BooleanLiteral(((Number) value).doubleValue() != 0);
return new LiteralExpression.BooleanLiteral(value != 0);

default:
throw new UnsupportedOperationException("Can't cast a boolean value into type of " + targetType);
Expand Down Expand Up @@ -336,13 +348,13 @@ public LiteralExpression<?> castTo(IDataType targetType) {
return new LiteralExpression.StringLiteral(value.toString());

case LONG:
return new LiteralExpression.LongLiteral(((Number) value).longValue());
return new LiteralExpression.LongLiteral(value.longValue());

case DOUBLE:
return new LiteralExpression.DoubleLiteral(value.doubleValue());

case BOOLEAN:
return new LiteralExpression.BooleanLiteral(((Number) value).doubleValue() != 0);
return new LiteralExpression.BooleanLiteral(value.doubleValue() != 0);

default:
throw new UnsupportedOperationException("Can't cast a boolean value into type of " + targetType);
Expand Down
1 change: 1 addition & 0 deletions dev/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<suppress files="[/\\]jooq[/\\]" checks=".*"/>
<suppress files="[/\\]generated-sources[/\\]" checks=".*"/>
<suppress files="[/\\]ast[/\\]" checks=".*"/>
<suppress files="[/\\]thrift-generated[/\\]" checks=".*"/>

<!-- Code copied from TestNG to apply a bugfix -->
<suppress checks="AvoidStaticImport" files="[\\/]org[\\/]testng[\\/]" />
Expand Down
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.bithon.component.commons.expression.IExpressionVisitor;
import org.bithon.component.commons.expression.serialization.ExpressionSerializer;
import org.bithon.server.alerting.common.evaluator.metric.IMetricEvaluator;
import org.bithon.server.metric.expression.ast.MetricExpression;
import org.bithon.server.metric.expression.ast.MetricAggregateExpression;

/**
* NOTE: When changes are made to this class,
Expand Down Expand Up @@ -52,7 +52,7 @@
public class AlertExpression implements IExpression {

private String id;
private MetricExpression metricExpression;
private MetricAggregateExpression metricExpression;
private IMetricEvaluator metricEvaluator;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.bithon.server.metric.expression.MetricExpressionBaseVisitor;
import org.bithon.server.metric.expression.MetricExpressionLexer;
import org.bithon.server.metric.expression.MetricExpressionParser;
import org.bithon.server.metric.expression.ast.MetricExpression;
import org.bithon.server.metric.expression.ast.MetricAggregateExpression;
import org.bithon.server.metric.expression.ast.MetricExpressionASTBuilder;

import java.util.List;
Expand Down Expand Up @@ -88,8 +88,8 @@ private static class MetricExpressionBuilder extends MetricExpressionBaseVisitor

@Override
public IExpression visitAtomicAlertExpression(MetricExpressionParser.AtomicAlertExpressionContext ctx) {
IExpression expression = MetricExpressionASTBuilder.build(ctx.metricExpression());
if (!(expression instanceof MetricExpression metricExpression)) {
IExpression expression = MetricExpressionASTBuilder.toAST(ctx.metricExpression());
if (!(expression instanceof MetricAggregateExpression metricExpression)) {
throw new InvalidExpressionException("Complex expression is not supported now.");
}

Expand Down Expand Up @@ -148,7 +148,7 @@ public IExpression visitLogicalAlertExpression(MetricExpressionParser.LogicalAle
}
}

private static IMetricEvaluator createMetricEvaluator(MetricExpression metricExpression) {
private static IMetricEvaluator createMetricEvaluator(MetricAggregateExpression metricExpression) {
LiteralExpression<?> expected = metricExpression.getExpected();
HumanReadableDuration offset = metricExpression.getOffset();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,4 @@ default boolean isVirtual() {
}

Period getTtl();


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020 bithon.org
*
* 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 org.bithon.server.datasource;

/**
* @author frank.chen021@outlook.com
* @date 2025/6/11 20:34
*/
public interface ISchemaProvider {
ISchema getSchema(String name) throws SchemaException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.bithon.server.datasource.query;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.bithon.server.datasource.query.pipeline.ColumnarTable;
import org.bithon.server.datasource.query.plan.logical.LogicalTableScan;
import org.bithon.server.datasource.query.plan.physical.IPhysicalPlan;
import org.bithon.server.datasource.query.result.ColumnarTable;

import java.util.List;

Expand All @@ -28,6 +30,10 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
public interface IDataSourceReader extends AutoCloseable {

default IPhysicalPlan plan(LogicalTableScan tableScan, Interval interval) {
throw new UnsupportedOperationException("This data source does not support logical plan execution");
}

ColumnarTable timeseries(Query query);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2020 bithon.org
*
* 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 org.bithon.server.datasource.query.plan.logical;

/**
* Base implementation of ILogicalPlanVisitor that provides default behavior
* and utility methods for common visitor operations.
* <p>
* This class can be extended to implement specific visitor functionality
* without having to implement all visitor methods from scratch.
*
* @param <T> the return type of the visitor methods
* @author frank.chen021@outlook.com
* @date 2025/6/4 23:31
*/
public abstract class BaseLogicalPlanVisitor<T> implements ILogicalPlanVisitor<T> {

/**
* Default implementation for visiting table scans.
* Can be overridden by subclasses to provide specific behavior.
*/
@Override
public T visitTableScan(LogicalTableScan tableScan) {
return defaultVisit(tableScan);
}

/**
* Default implementation for visiting aggregates.
* Recursively visit the input plan.
* It Can be overridden by subclasses to provide specific behavior.
*/
@Override
public T visitAggregate(LogicalAggregate aggregate) {
aggregate.input().accept(this);
return defaultVisit(aggregate);
}

/**
* Default implementation for visiting binary operations.
* Recursively visits both left and right operands.
* It Can be overridden by subclasses to provide specific behavior.
*/
@Override
public T visitBinaryOp(LogicalBinaryOp binaryOp) {
binaryOp.left().accept(this);
binaryOp.right().accept(this);
return defaultVisit(binaryOp);
}

/**
* Default implementation for visiting scalars.
* Can be overridden by subclasses to provide specific behavior.
*/
@Override
public T visitScalar(LogicalScalar scalar) {
return defaultVisit(scalar);
}

/**
* Default implementation for visiting filters.
* Recursively visits both left and right operands.
* It Can be overridden by subclasses to provide specific behavior.
*/
@Override
public T visitFilter(LogicalFilter filter) {
filter.left().accept(this);
filter.right().accept(this);
return defaultVisit(filter);
}

/**
* Default behavior for all visit methods.
* Subclasses can override this to provide common default behavior,
* or override individual visit methods for specific behavior.
*
* @param plan the logical plan being visited
* @return the default result
*/
protected abstract T defaultVisit(ILogicalPlan plan);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@
* limitations under the License.
*/

package org.bithon.server.datasource.query.pipeline;


import java.util.concurrent.CompletableFuture;
package org.bithon.server.datasource.query.plan.logical;

/**
* @author frank.chen021@outlook.com
* @date 4/4/25 3:47 pm
* @date 2025/6/4 23:33
*/
public interface IQueryStep {

boolean isScalar();

CompletableFuture<PipelineQueryResult> execute() throws Exception;
public enum BinaryOp {
ADD, SUB, MUL, DIV
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 bithon.org
*
* 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 org.bithon.server.datasource.query.plan.logical;

/**
* @author frank.chen021@outlook.com
* @date 2025/6/4 23:31
*/
public sealed interface ILogicalPlan
permits LogicalTableScan, LogicalAggregate, LogicalBinaryOp,
LogicalScalar, LogicalFilter {

/**
* Accept a visitor for the visitor pattern implementation
* @param visitor the visitor to accept
* @param <T> the return type of the visitor
* @return the result of visiting this logical plan
*/
<T> T accept(ILogicalPlanVisitor<T> visitor);
}

Loading
Loading