Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion .claude/reference/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ ChunkTimeInterval = "7 days" // ChunkTimeIntervalLong = 604_800_000_000L
ReorderPolicyScheduleInterval = "1 day"
ReorderPolicyMaxRetries = -1 // indefinite
ReorderPolicyMaxRuntime = "00:00:00" // no limit
ReorderPolicyRetryPeriod = "00:05:00"
```

## Design Library Structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ApplyAnnotations(DatabaseTable table, object featureInfo)
table[ReorderPolicyAnnotations.MaxRetries] = policyInfo.MaxRetries;
}

if (policyInfo.RetryPeriod != DefaultValues.ReorderPolicyRetryPeriod)
if (policyInfo.RetryPeriod != DefaultValues.ReorderPolicyScheduleInterval)
{
table[ReorderPolicyAnnotations.RetryPeriod] = policyInfo.RetryPeriod;
}
Expand Down
1 change: 0 additions & 1 deletion src/Eftdb/DefaultValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ public static class DefaultValues
public const string ReorderPolicyScheduleInterval = "1 day";
public const int ReorderPolicyMaxRetries = -1;
public const string ReorderPolicyMaxRuntime = "00:00:00";
public const string ReorderPolicyRetryPeriod = "00:05:00";
}
}
6 changes: 3 additions & 3 deletions src/Eftdb/Generators/HypertableOperationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,16 @@ private static string WrapCommunityFeatures(List<string> sqlStatements)
/// Escapes existing double quotes.
/// Example: TenantId -> "TenantId"
/// </summary>
private static string QuoteIdentifier(string identifier)
private string QuoteIdentifier(string identifier)
{
return $"\"{identifier.Replace("\"", "\"\"")}\"";
return $"{quoteString}{identifier.Replace("\"", "\"\"")}{quoteString}";
}

/// <summary>
/// Quotes the column name within an ORDER BY clause while preserving direction/nulls.
/// Example: Timestamp DESC -> "Timestamp" DESC
/// </summary>
private static string QuoteOrderByList(IEnumerable<string> orderByClauses)
private string QuoteOrderByList(IEnumerable<string> orderByClauses)
{
return string.Join(", ", orderByClauses.Select(clause =>
{
Expand Down
11 changes: 5 additions & 6 deletions src/Eftdb/Generators/ReorderPolicyOperationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,17 @@ public List<string> Generate(DropReorderPolicyOperation operation)
private static List<string> BuildAlterJobClauses(AddReorderPolicyOperation operation)
{
List<string> clauses = [];
// Assuming DefaultValues is accessible or static constants
// Note: You may need to adjust the default value comparisons if DefaultValues isn't available
if (!string.IsNullOrWhiteSpace(operation.ScheduleInterval)) // && operation.ScheduleInterval != DefaultValues.ReorderPolicyScheduleInterval)

if (!string.IsNullOrWhiteSpace(operation.ScheduleInterval))
clauses.Add($"schedule_interval => INTERVAL '{operation.ScheduleInterval}'");

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

if (operation.MaxRetries != null) // && operation.MaxRetries != DefaultValues.ReorderPolicyMaxRetries)
if (operation.MaxRetries != null)
clauses.Add($"max_retries => {operation.MaxRetries}");

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

return clauses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IEnumerable<AddReorderPolicyOperation> GetReorderPolicies(IRelatio
ScheduleInterval = entityType.FindAnnotation(ReorderPolicyAnnotations.ScheduleInterval)?.Value as string ?? DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime = entityType.FindAnnotation(ReorderPolicyAnnotations.MaxRuntime)?.Value as string ?? DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries = entityType.FindAnnotation(ReorderPolicyAnnotations.MaxRetries)?.Value as int? ?? DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod = entityType.FindAnnotation(ReorderPolicyAnnotations.RetryPeriod)?.Value as string ?? DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod = entityType.FindAnnotation(ReorderPolicyAnnotations.RetryPeriod)?.Value as string ?? DefaultValues.ReorderPolicyScheduleInterval
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Should_Extract_Minimal_ReorderPolicy()
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operation.ScheduleInterval);
Assert.Equal(DefaultValues.ReorderPolicyMaxRuntime, operation.MaxRuntime);
Assert.Equal(DefaultValues.ReorderPolicyMaxRetries, operation.MaxRetries);
Assert.Equal(DefaultValues.ReorderPolicyRetryPeriod, operation.RetryPeriod);
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operation.RetryPeriod);
}

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

Assert.Single(operations);
Assert.Equal(DefaultValues.ReorderPolicyRetryPeriod, operations[0].RetryPeriod);
Assert.Equal(DefaultValues.ReorderPolicyScheduleInterval, operations[0].RetryPeriod);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public void DesignTime_Create_WithCompressionSegmentBy_GeneratesCorrectCode()
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""tenant_id"", ""device_id""'')';
EXECUTE 'ALTER TABLE """"public"""".""""segmented_data"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""tenant_id"""", """"device_id""""'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down Expand Up @@ -418,7 +418,7 @@ public void DesignTime_Create_WithCompressionOrderBy_GeneratesCorrectCode()
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""time"" DESC, ""value"" ASC NULLS LAST'')';
EXECUTE 'ALTER TABLE """"public"""".""""ordered_data"""" SET (timescaledb.compress = true, timescaledb.compress_orderby = ''""""time"""" DESC, """"value"""" ASC NULLS LAST'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down Expand Up @@ -862,7 +862,7 @@ public void DesignTime_Alter_AddingCompressionSegmentBy_GeneratesCorrectCode()
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""device_id""'')';
EXECUTE 'ALTER TABLE """"public"""".""""metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""device_id""""'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Generate_Create_With_Compression_Segment_And_OrderBy_Generates_Corre
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""TenantId"", ""DeviceId""'', timescaledb.compress_orderby = ''""Timestamp"" DESC, ""Value"" ASC NULLS LAST'')';
EXECUTE 'ALTER TABLE """"public"""".""""CompressedTable"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""TenantId"""", """"DeviceId""""'', timescaledb.compress_orderby = ''""""Timestamp"""" DESC, """"Value"""" ASC NULLS LAST'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down Expand Up @@ -222,7 +222,7 @@ public void Generate_Alter_Adding_Compression_SegmentBy_Generates_Correct_Sql()
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""DeviceId""'')';
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress = true, timescaledb.compress_segmentby = ''""""DeviceId""""'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down Expand Up @@ -257,7 +257,7 @@ public void Generate_Alter_Modifying_Compression_OrderBy_Generates_Correct_Sql()
license := current_setting('timescaledb.license', true);

IF license IS NULL OR license != 'apache' THEN
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""Timestamp"" DESC'')';
EXECUTE 'ALTER TABLE """"public"""".""""Metrics"""" SET (timescaledb.compress_orderby = ''""""Timestamp"""" DESC'')';
ELSE
RAISE WARNING 'Skipping Community Edition features (compression, chunk skipping) - not available in Apache Edition';
END IF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public async Task Should_Handle_LargeDataset()
for (int i = 0; i < 100; i++)
{
DateTime timestamp = baseTime.AddMinutes(i);
valueRows.Add($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})");
valueRows.Add(FormattableString.Invariant($"('{timestamp:yyyy-MM-dd HH:mm:ss}+00', {i % 10}, {15.0 + i * 0.1})"));
}

string sql = $@"INSERT INTO ""PerformanceTest"" (""Timestamp"", ""SensorId"", ""Value"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Should_Apply_Minimal_ReorderPolicy_Annotations()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -60,7 +60,7 @@ public void Should_Apply_HasReorderPolicy_Always_True()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -88,7 +88,7 @@ public void Should_Apply_IndexName_Annotation()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -114,7 +114,7 @@ public void Should_Apply_InitialStart_Annotation()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -139,7 +139,7 @@ public void Should_Not_Apply_InitialStart_When_Null()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -164,7 +164,7 @@ public void Should_Apply_ScheduleInterval_When_Different_From_Default()
ScheduleInterval: "7 days",
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -189,7 +189,7 @@ public void Should_Not_Apply_ScheduleInterval_When_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval, // "1 day"
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -219,7 +219,7 @@ public void Should_Apply_Various_ScheduleInterval_Formats(string scheduleInterva
ScheduleInterval: scheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -244,7 +244,7 @@ public void Should_Apply_MaxRuntime_When_Different_From_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: "01:00:00",
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -269,7 +269,7 @@ public void Should_Not_Apply_MaxRuntime_When_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime, // "00:00:00"
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -294,7 +294,7 @@ public void Should_Apply_MaxRetries_When_Different_From_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: 5,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -319,7 +319,7 @@ public void Should_Not_Apply_MaxRetries_When_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries, // -1
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -344,7 +344,7 @@ public void Should_Apply_MaxRetries_Zero()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: 0,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -373,7 +373,7 @@ public void Should_Apply_MaxRetries_Positive_Values(int maxRetries)
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: maxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -423,7 +423,7 @@ public void Should_Not_Apply_RetryPeriod_When_Default()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod // "00:05:00"
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval // "00:05:00"
);

// Act
Expand Down Expand Up @@ -598,7 +598,7 @@ public void Should_Preserve_Existing_Table_Properties()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down Expand Up @@ -629,7 +629,7 @@ public void Should_Handle_IndexName_With_Schema_Prefix()
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand All @@ -655,7 +655,7 @@ public void Should_Handle_Various_InitialStart_DateTimes(DateTime initialStart)
ScheduleInterval: DefaultValues.ReorderPolicyScheduleInterval,
MaxRuntime: DefaultValues.ReorderPolicyMaxRuntime,
MaxRetries: DefaultValues.ReorderPolicyMaxRetries,
RetryPeriod: DefaultValues.ReorderPolicyRetryPeriod
RetryPeriod: DefaultValues.ReorderPolicyScheduleInterval
);

// Act
Expand Down
Loading