Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -42,7 +42,7 @@ public class TimescaleDBProperties {
/**
* TimescaleDB超表函数所在的位置
*/
private String functionSchema = "public";
private String functionSchema = this.schema;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样并不准确. 重写get方法更合适?


/**
* 写入缓冲区配置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static NativeSelectColumn createTimeGroupColumn(long startWith, Interval
.toLowerCase();

return NativeSelectColumn
.of(functionSchema + ".time_bucket('" + unit + "',timestamp)");
.of("\"" + functionSchema + "\"" + ".time_bucket('" + unit + "',timestamp)");
}

public static TimeSeriesData convertToTimeSeriesData(Record record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jetlinks.community.timescaledb.TimescaleDBOperations;
import org.jetlinks.community.timescaledb.TimescaleDBProperties;
import org.jetlinks.community.timescaledb.metadata.TimescaleDBDialectProvider;
import org.jetlinks.community.timescaledb.metadata.TimescaleDBPropertiesFeature;
import org.springframework.beans.BeansException;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void init() {
RDBDatabaseMetadata database = new RDBDatabaseMetadata(Dialect.POSTGRES);
database.addFeature(sqlExecutor);
database.addFeature(ReactiveSyncSqlExecutor.of(sqlExecutor));

database.addFeature(TimescaleDBPropertiesFeature.of(properties));
RDBSchemaMetadata schema = TimescaleDBDialectProvider.GLOBAL.createSchema(properties.getSchema());
database.addSchema(schema);
database.setCurrentSchema(schema);
Expand All @@ -91,6 +92,7 @@ public void init() {
.create("TimescaleDB", datasource);
disposable.add(dataSource);
database = dataSource.operator();
database.getMetadata().addFeature(TimescaleDBPropertiesFeature.of(properties));
}
writer = new DefaultTimescaleDBDataWriter(database, properties.getWriteBuffer());
writer.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ private SqlRequest createCreateRetentionPolicySQL(RDBTableMetadata table, Create

String interval = createHypertable.getInterval().getNumber().intValue() + " "
+ createHypertable.getInterval().getUnit().name().toLowerCase();
String functionSchema = table.getFeatureNow(FunctionSchema.ID)
String functionSchema = table.getSchema()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 table.findFeature就行了?

.getDatabase()
.getFeatureNow(TimescaleDBPropertiesFeature.ID)
.getProperties()
.getFunctionSchema();

return SqlRequests.of(
"SELECT " + functionSchema + ".add_retention_policy( ? , INTERVAL '" + interval + "')",
"SELECT " + "\"" + functionSchema + "\"" + ".add_retention_policy( ? , INTERVAL '" + interval + "')",
table.getFullName()
);
}
Expand All @@ -55,10 +58,13 @@ private SqlRequest createCreateHypertableSQL(RDBTableMetadata table, CreateHyper

String interval = createHypertable.getChunkTimeInterval().getNumber().intValue() + " "
+ createHypertable.getChunkTimeInterval().getUnit().name().toLowerCase();
String functionSchema = table.getFeatureNow(FunctionSchema.ID)
String functionSchema = table.getSchema()
.getDatabase()
.getFeatureNow(TimescaleDBPropertiesFeature.ID)
.getProperties()
.getFunctionSchema();
return SqlRequests.of(
"SELECT " + functionSchema + ".create_hypertable( ? , ? , chunk_time_interval => INTERVAL '" + interval + "')",
"SELECT " + "\"" + functionSchema + "\"" + ".create_hypertable( ? , ? , chunk_time_interval => INTERVAL '" + interval + "')",
table.getFullName(),
table.getColumnNow(createHypertable.getColumn()).getName()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import org.hswebframework.ezorm.core.FeatureId;
import org.hswebframework.ezorm.core.FeatureType;
import org.hswebframework.ezorm.core.meta.Feature;
import org.jetlinks.community.timescaledb.TimescaleDBProperties;

@AllArgsConstructor(staticName = "of")
@Getter
public class FunctionSchema implements Feature, FeatureType {
public class TimescaleDBPropertiesFeature implements Feature, FeatureType {

public static final FeatureId<FunctionSchema> ID = FeatureId.of("FunctionSchema");
public static final FeatureId<TimescaleDBPropertiesFeature> ID = FeatureId.of("TimescaleDBPropertiesFeature");

private final String functionSchema;
private final TimescaleDBProperties properties;

@Override
public String getId() {
Expand All @@ -21,7 +22,7 @@ public String getId() {

@Override
public String getName() {
return "FunctionSchema";
return "TimescaleDBPropertiesFeature";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.crud.query.QueryHelper;
import org.jetlinks.community.timescaledb.metadata.FunctionSchema;
import org.jetlinks.core.metadata.EventMetadata;
import org.jetlinks.community.timescaledb.metadata.TimescaleDBPropertiesFeature;
import org.jetlinks.core.things.ThingsRegistry;
import org.jetlinks.community.things.data.AggregationRequest;
import org.jetlinks.community.things.data.PropertyAggregation;
Expand All @@ -38,7 +37,6 @@
import org.jetlinks.community.things.data.operations.ColumnModeQueryOperationsBase;
import org.jetlinks.community.things.data.operations.DataSettings;
import org.jetlinks.community.things.data.operations.MetricBuilder;
import org.jetlinks.community.things.data.operations.RowModeQueryOperationsBase;
import org.jetlinks.community.timescaledb.TimescaleDBUtils;
import org.jetlinks.community.timeseries.TimeSeriesData;
import org.jetlinks.community.timeseries.query.Aggregation;
Expand Down Expand Up @@ -124,7 +122,10 @@ static Flux<AggregationData> doAggregation0(DatabaseOperator database,
NativeSelectColumn column = createTimeGroupColumn(
request.getFrom().getTime(),
request.getInterval(),
database.getMetadata().getTable(metric).get().getFeatureNow(FunctionSchema.ID).getFunctionSchema()
database.getMetadata()
.getFeatureNow(TimescaleDBPropertiesFeature.ID)
.getProperties()
.getFunctionSchema()
);
query.groupBy(column);
query.select(column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
import org.hswebframework.web.api.crud.entity.PagerResult;
import org.hswebframework.web.api.crud.entity.QueryParamEntity;
import org.hswebframework.web.crud.query.QueryHelper;
import org.jetlinks.community.timescaledb.metadata.FunctionSchema;
import org.jetlinks.core.metadata.EventMetadata;
import org.jetlinks.community.timescaledb.metadata.TimescaleDBPropertiesFeature;
import org.jetlinks.core.things.ThingsRegistry;
import org.jetlinks.community.things.data.AggregationRequest;
import org.jetlinks.community.things.data.PropertyAggregation;
Expand All @@ -50,8 +49,6 @@
import java.util.*;
import java.util.function.Function;

import static org.jetlinks.community.timescaledb.thing.TimescaleDBColumnModeQueryOperations.doAggregation0;

@Slf4j
public class TimescaleDBRowModeQueryOperations extends RowModeQueryOperationsBase {
private final DatabaseOperator database;
Expand Down Expand Up @@ -119,7 +116,10 @@ protected Flux<AggregationData> doAggregation(String metric,
NativeSelectColumn column = TimescaleDBUtils.createTimeGroupColumn(
request.getFrom().getTime(),
request.getInterval(),
database.getMetadata().getTable(metric).get().getFeatureNow(FunctionSchema.ID).getFunctionSchema()
database.getMetadata()
.getFeatureNow(TimescaleDBPropertiesFeature.ID)
.getProperties()
.getFunctionSchema()
);

query.groupBy(column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hswebframework.ezorm.rdb.metadata.RDBIndexMetadata;
import org.hswebframework.ezorm.rdb.operator.ddl.TableBuilder;
import org.jetlinks.community.timescaledb.TimescaleDBProperties;
import org.jetlinks.community.timescaledb.metadata.FunctionSchema;
import org.jetlinks.core.metadata.PropertyMetadata;
import org.jetlinks.community.Interval;
import org.jetlinks.community.things.data.ThingsDataConstants;
Expand Down Expand Up @@ -86,7 +85,6 @@ public Mono<Void> registerMetadata(TimeSeriesMetadata metadata) {
.ddl()
.createOrAlter(tableName)
.custom(table -> {
table.addFeature(FunctionSchema.of(timescaleDBProperties.getFunctionSchema()));
table.addFeature(new CreateHypertable(ThingsDataConstants.COLUMN_TIMESTAMP, properties.getChunkTimeInterval()));
Interval interval = properties.getRetentionPolicy(tableName);
if (interval != null && interval.getNumber().longValue() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.hswebframework.ezorm.rdb.operator.dml.query.SelectColumn;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.id.IDGenerator;
import org.jetlinks.community.timescaledb.metadata.FunctionSchema;
import org.jetlinks.community.timescaledb.metadata.TimescaleDBPropertiesFeature;
import org.jetlinks.core.utils.Reactors;
import org.jetlinks.community.things.data.ThingsDataConstants;
import org.jetlinks.community.timescaledb.TimescaleDBOperations;
Expand Down Expand Up @@ -114,7 +114,14 @@ public Flux<AggregationData> aggregation(AggregationQueryParam param) {
for (Group group : groups) {
if (group instanceof TimeGroup) {
_timeGroup = ((TimeGroup) group);
NativeSelectColumn column = TimescaleDBUtils.createTimeGroupColumn(startWith, _timeGroup.getInterval(),operations.database().getMetadata().getTable(metric).get().getFeatureNow(FunctionSchema.ID).getFunctionSchema());
NativeSelectColumn column = TimescaleDBUtils.createTimeGroupColumn(startWith,
_timeGroup.getInterval(),
operations
.database()
.getMetadata()
.getFeatureNow(TimescaleDBPropertiesFeature.ID)
.getProperties()
.getFunctionSchema());
column.setColumn(ThingsDataConstants.COLUMN_TIMESTAMP);
column.setAlias(group.getAlias());
query.select(column);
Expand Down