Skip to content

Commit 931960c

Browse files
Merge pull request #37 from cmdscale/fix/reorder_policies
Fix/reorder policies
2 parents ea30294 + a8213ca commit 931960c

File tree

11 files changed

+37
-40
lines changed

11 files changed

+37
-40
lines changed

.claude/reference/architecture.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ ChunkTimeInterval = "7 days" // ChunkTimeIntervalLong = 604_800_000_000L
129129
ReorderPolicyScheduleInterval = "1 day"
130130
ReorderPolicyMaxRetries = -1 // indefinite
131131
ReorderPolicyMaxRuntime = "00:00:00" // no limit
132-
ReorderPolicyRetryPeriod = "00:05:00"
133132
```
134133

135134
## Design Library Structure

src/Eftdb.Design/Scaffolding/ReorderPolicyAnnotationApplier.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void ApplyAnnotations(DatabaseTable table, object featureInfo)
4040
table[ReorderPolicyAnnotations.MaxRetries] = policyInfo.MaxRetries;
4141
}
4242

43-
if (policyInfo.RetryPeriod != DefaultValues.ReorderPolicyRetryPeriod)
43+
if (policyInfo.RetryPeriod != DefaultValues.ReorderPolicyScheduleInterval)
4444
{
4545
table[ReorderPolicyAnnotations.RetryPeriod] = policyInfo.RetryPeriod;
4646
}

src/Eftdb/DefaultValues.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ public static class DefaultValues
1111
public const string ReorderPolicyScheduleInterval = "1 day";
1212
public const int ReorderPolicyMaxRetries = -1;
1313
public const string ReorderPolicyMaxRuntime = "00:00:00";
14-
public const string ReorderPolicyRetryPeriod = "00:05:00";
1514
}
1615
}

src/Eftdb/Generators/HypertableOperationGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ private static string WrapCommunityFeatures(List<string> sqlStatements)
309309
/// Escapes existing double quotes.
310310
/// Example: TenantId -> "TenantId"
311311
/// </summary>
312-
private static string QuoteIdentifier(string identifier)
312+
private string QuoteIdentifier(string identifier)
313313
{
314-
return $"\"{identifier.Replace("\"", "\"\"")}\"";
314+
return $"{quoteString}{identifier.Replace("\"", "\"\"")}{quoteString}";
315315
}
316316

317317
/// <summary>
318318
/// Quotes the column name within an ORDER BY clause while preserving direction/nulls.
319319
/// Example: Timestamp DESC -> "Timestamp" DESC
320320
/// </summary>
321-
private static string QuoteOrderByList(IEnumerable<string> orderByClauses)
321+
private string QuoteOrderByList(IEnumerable<string> orderByClauses)
322322
{
323323
return string.Join(", ", orderByClauses.Select(clause =>
324324
{

src/Eftdb/Generators/ReorderPolicyOperationGenerator.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ public List<string> Generate(DropReorderPolicyOperation operation)
9090
private static List<string> BuildAlterJobClauses(AddReorderPolicyOperation operation)
9191
{
9292
List<string> clauses = [];
93-
// Assuming DefaultValues is accessible or static constants
94-
// Note: You may need to adjust the default value comparisons if DefaultValues isn't available
95-
if (!string.IsNullOrWhiteSpace(operation.ScheduleInterval)) // && operation.ScheduleInterval != DefaultValues.ReorderPolicyScheduleInterval)
93+
94+
if (!string.IsNullOrWhiteSpace(operation.ScheduleInterval))
9695
clauses.Add($"schedule_interval => INTERVAL '{operation.ScheduleInterval}'");
9796

98-
if (!string.IsNullOrWhiteSpace(operation.MaxRuntime)) // && operation.MaxRuntime != DefaultValues.ReorderPolicyMaxRuntime)
97+
if (!string.IsNullOrWhiteSpace(operation.MaxRuntime))
9998
clauses.Add($"max_runtime => INTERVAL '{operation.MaxRuntime}'");
10099

101-
if (operation.MaxRetries != null) // && operation.MaxRetries != DefaultValues.ReorderPolicyMaxRetries)
100+
if (operation.MaxRetries != null)
102101
clauses.Add($"max_retries => {operation.MaxRetries}");
103102

104-
if (!string.IsNullOrWhiteSpace(operation.RetryPeriod)) // && operation.RetryPeriod != DefaultValues.ReorderPolicyRetryPeriod)
103+
if (!string.IsNullOrWhiteSpace(operation.RetryPeriod))
105104
clauses.Add($"retry_period => INTERVAL '{operation.RetryPeriod}'");
106105

107106
return clauses;

src/Eftdb/Internals/Features/ReorderPolicies/ReorderPolicyModelExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static IEnumerable<AddReorderPolicyOperation> GetReorderPolicies(IRelatio
4040
ScheduleInterval = entityType.FindAnnotation(ReorderPolicyAnnotations.ScheduleInterval)?.Value as string ?? DefaultValues.ReorderPolicyScheduleInterval,
4141
MaxRuntime = entityType.FindAnnotation(ReorderPolicyAnnotations.MaxRuntime)?.Value as string ?? DefaultValues.ReorderPolicyMaxRuntime,
4242
MaxRetries = entityType.FindAnnotation(ReorderPolicyAnnotations.MaxRetries)?.Value as int? ?? DefaultValues.ReorderPolicyMaxRetries,
43-
RetryPeriod = entityType.FindAnnotation(ReorderPolicyAnnotations.RetryPeriod)?.Value as string ?? DefaultValues.ReorderPolicyRetryPeriod
43+
RetryPeriod = entityType.FindAnnotation(ReorderPolicyAnnotations.RetryPeriod)?.Value as string ?? DefaultValues.ReorderPolicyScheduleInterval
4444
};
4545
}
4646
}

tests/Eftdb.Tests/Extractors/ReorderPolicyModelExtractorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void Should_Extract_Minimal_ReorderPolicy()
6565
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operation.ScheduleInterval);
6666
Assert.Equal(DefaultValues.ReorderPolicyMaxRuntime, operation.MaxRuntime);
6767
Assert.Equal(DefaultValues.ReorderPolicyMaxRetries, operation.MaxRetries);
68-
Assert.Equal(DefaultValues.ReorderPolicyRetryPeriod, operation.RetryPeriod);
68+
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operation.RetryPeriod);
6969
}
7070

7171
#endregion
@@ -555,7 +555,7 @@ public void Should_Use_Default_RetryPeriod_When_Not_Specified()
555555
List<AddReorderPolicyOperation> operations = [.. ReorderPolicyModelExtractor.GetReorderPolicies(relationalModel)];
556556

557557
Assert.Single(operations);
558-
Assert.Equal(DefaultValues.ReorderPolicyRetryPeriod, operations[0].RetryPeriod);
558+
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operations[0].RetryPeriod);
559559
}
560560

561561
#endregion

tests/Eftdb.Tests/Generators/HypertableOperationGeneratorComprehensiveTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void DesignTime_Create_WithCompressionSegmentBy_GeneratesCorrectCode()
383383
license := current_setting('timescaledb.license', true);
384384
385385
IF license IS NULL OR license != 'apache' THEN
386-
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""tenant_id"", ""device_id""'')';
386+
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""tenant_id"""", """"device_id""""'')';
387387
ELSE
388388
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
389389
END IF;
@@ -418,7 +418,7 @@ public void DesignTime_Create_WithCompressionOrderBy_GeneratesCorrectCode()
418418
license := current_setting('timescaledb.license', true);
419419
420420
IF license IS NULL OR license != 'apache' THEN
421-
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""time"" DESC, ""value"" ASC NULLS LAST'')';
421+
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""""time"""" DESC, """"value"""" ASC NULLS LAST'')';
422422
ELSE
423423
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
424424
END IF;
@@ -862,7 +862,7 @@ public void DesignTime_Alter_AddingCompressionSegmentBy_GeneratesCorrectCode()
862862
license := current_setting('timescaledb.license', true);
863863
864864
IF license IS NULL OR license != 'apache' THEN
865-
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""device_id""'')';
865+
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""device_id""""'')';
866866
ELSE
867867
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
868868
END IF;

tests/Eftdb.Tests/Generators/HypertableOperationGeneratorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void Generate_Create_With_Compression_Segment_And_OrderBy_Generates_Corre
187187
license := current_setting('timescaledb.license', true);
188188
189189
IF license IS NULL OR license != 'apache' THEN
190-
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""TenantId"", ""DeviceId""'', timescaledb.compress_orderby = ''""Timestamp"" DESC, ""Value"" ASC NULLS LAST'')';
190+
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""TenantId"""", """"DeviceId""""'', timescaledb.compress_orderby = ''""""Timestamp"""" DESC, """"Value"""" ASC NULLS LAST'')';
191191
ELSE
192192
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
193193
END IF;
@@ -222,7 +222,7 @@ public void Generate_Alter_Adding_Compression_SegmentBy_Generates_Correct_Sql()
222222
license := current_setting('timescaledb.license', true);
223223
224224
IF license IS NULL OR license != 'apache' THEN
225-
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""DeviceId""'')';
225+
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""DeviceId""""'')';
226226
ELSE
227227
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
228228
END IF;
@@ -257,7 +257,7 @@ public void Generate_Alter_Modifying_Compression_OrderBy_Generates_Correct_Sql()
257257
license := current_setting('timescaledb.license', true);
258258
259259
IF license IS NULL OR license != 'apache' THEN
260-
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""Timestamp"" DESC'')';
260+
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""""Timestamp"""" DESC'')';
261261
ELSE
262262
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
263263
END IF;

tests/Eftdb.Tests/Integration/HypertableIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public async Task Should_Handle_LargeDataset()
980980
for (int i = 0; i < 100; i++)
981981
{
982982
DateTime timestamp = baseTime.AddMinutes(i);
983-
valueRows.Add($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})");
983+
valueRows.Add(FormattableString.Invariant($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})"));
984984
}
985985

986986
string sql = $@"INSERT INTO ""PerformanceTest"" (""Timestamp"", ""SensorId"", ""Value"")

0 commit comments

Comments
 (0)