-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(timescaledb): 支持配置TimescaleDB函数所在的schema #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,15 +40,15 @@ public static String getTableName(String name) { | |
| return ThingsDatabaseUtils.createTableName(name); | ||
| } | ||
|
|
||
| public static NativeSelectColumn createTimeGroupColumn(long startWith, Interval interval) { | ||
| public static NativeSelectColumn createTimeGroupColumn(long startWith, Interval interval, String functionSchema) { | ||
|
|
||
| String unit = interval.getNumber().intValue() + " " + interval | ||
| .getUnit() | ||
| .name() | ||
| .toLowerCase(); | ||
|
|
||
| return NativeSelectColumn | ||
| .of("time_bucket('" + unit + "',timestamp)"); | ||
| .of(functionSchema + ".time_bucket('" + unit + "',timestamp)"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 括起来更好? 有的schema 有 |
||
| } | ||
|
|
||
| public static TimeSeriesData convertToTimeSeriesData(Record record) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.jetlinks.community.timescaledb.metadata; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.hswebframework.ezorm.core.FeatureId; | ||
| import org.hswebframework.ezorm.core.FeatureType; | ||
| import org.hswebframework.ezorm.core.meta.Feature; | ||
|
|
||
| @AllArgsConstructor(staticName = "of") | ||
| @Getter | ||
| public class FunctionSchema implements Feature, FeatureType { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建立直接传 |
||
|
|
||
| public static final FeatureId<FunctionSchema> ID = FeatureId.of("FunctionSchema"); | ||
|
|
||
| private final String functionSchema; | ||
|
|
||
| @Override | ||
| public String getId() { | ||
| return ID.getId(); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "FunctionSchema"; | ||
| } | ||
|
|
||
| @Override | ||
| public FeatureType getType() { | ||
| return this; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +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.core.things.ThingsRegistry; | ||
| import org.jetlinks.community.things.data.AggregationRequest; | ||
|
|
@@ -122,7 +123,8 @@ static Flux<AggregationData> doAggregation0(DatabaseOperator database, | |
| if (request.getInterval() != null) { | ||
| NativeSelectColumn column = createTimeGroupColumn( | ||
| request.getFrom().getTime(), | ||
| request.getInterval() | ||
| request.getInterval(), | ||
| database.getMetadata().getTable(metric).get().getFeatureNow(FunctionSchema.ID).getFunctionSchema() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 某些特殊情况下没创建表时会产生错误. |
||
| ); | ||
| query.groupBy(column); | ||
| query.select(column); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,8 @@ | |
| import org.hswebframework.ezorm.rdb.codec.DateTimeCodec; | ||
| 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; | ||
|
|
@@ -48,6 +50,8 @@ public class TimescaleDBTimeSeriesManager implements TimeSeriesManager { | |
|
|
||
| private final TimescaleDBOperations operations; | ||
|
|
||
| private final TimescaleDBProperties timescaleDBProperties; | ||
|
|
||
| @Override | ||
| public TimeSeriesService getService(TimeSeriesMetric metric) { | ||
| return getService(metric.getId()); | ||
|
|
@@ -82,6 +86,7 @@ public Mono<Void> registerMetadata(TimeSeriesMetadata metadata) { | |
| .ddl() | ||
| .createOrAlter(tableName) | ||
| .custom(table -> { | ||
| table.addFeature(FunctionSchema.of(timescaleDBProperties.getFunctionSchema())); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议创建database 时直接放到 database或者schema中 |
||
| table.addFeature(new CreateHypertable(ThingsDataConstants.COLUMN_TIMESTAMP, properties.getChunkTimeInterval())); | ||
| Interval interval = properties.getRetentionPolicy(tableName); | ||
| if (interval != null && interval.getNumber().longValue() > 0) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认应该为null. 为null时使用schema, 否则只配置了schema的情况下, 可能有问题.