build: Downgrade new DataStream code from net8 -> net7

The AddColumnsStream, SortStream, and requisite yacc/lex grammar were
originally added to a new branch, off of development, which is on net8.
I forgot to change it to net7 when I cherry-picked the commits for the
regular development branch.

It's wasn't quite as simple as flipping net8 -> net7 in csproj files,
because I was eager to use new language features only available in net8!
Namely, primary constructors and collection expressions.
This commit is contained in:
John Colvin committed 2024-02-08 14:24:31 -06:00
1 parent d0ddc1d57b
commit 8660dea85a
10 files changed
+41 -25

No files matched your search

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
@@ -1,15 +1,21 @@
namespace Bts.ColumnExpressions;
public class ColumnExpression(string name, Type? type = null, object? value = null) {
public string Name { get; } = name;
public class ColumnExpression {
public ColumnExpression(string name, Type? type = null, object? value = null) {
Name = name;
Type = type
?? value?.GetType()
?? throw new ArgumentException(
"Type must be specified explicitly when value is null", nameof(type));
Value = value
?? DBNull.Value;
}
public Type Type { get; } = type
?? value?.GetType()
?? throw new ArgumentException(
"Type must be specified explicitly when value is null", nameof(type));
public string Name { get; }
public object Value { get; } = value
?? DBNull.Value;
public Type Type { get; }
public object Value { get; }
public static ColumnExpression Create<T>(string name, T value, Type? type = null) {
// Try to convert value to 'type' to verify they are compatible
@@ -29,7 +29,7 @@
%%
ColumnExpressions :
ColumnExpression { $$ = [$1]; }
ColumnExpression { $$ = ImmutableList.CreateRange(new[] { $1 }); }
| ColumnExpressions ColumnExpression { $$ = $1.Add($2); }
;
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
@@ -1,6 +1,11 @@
namespace Bts.ColumnSortExpressions;
public class ColumnSortExpression(string name, bool isAscending = true) {
public string Name { get; } = name;
public bool IsAscending { get; } = isAscending;
public class ColumnSortExpression {
public ColumnSortExpression(string name, bool isAscending = true) {
Name = name;
IsAscending = isAscending;
}
public string Name { get; }
public bool IsAscending { get; }
}
@@ -18,7 +18,7 @@
%%
Columns :
Column { $$ = [$1]; }
Column { $$ = ImmutableList.CreateRange(new[] { $1 }); }
| Columns Column { $$ = $1.Add($2); }
;
@@ -1,4 +1,6 @@
namespace BCG;
public class AddColumnsStream(ViewStream vs, string columnDef)
: MapStream(vs, new ColumnAdder(columnDef)) { }
public class AddColumnsStream : MapStream {
public AddColumnsStream(ViewStream vs, string columnDef)
: base(vs, new ColumnAdder(columnDef)) { }
}
@@ -13,14 +13,16 @@ namespace BCG;
/// <param name="columnsExpression">
/// String represting the columns to add to the output table
/// </param>
public class ColumnAdder(string columnsExpression) : IStreamMapper {
public class ColumnAdder : IStreamMapper {
// Store tuples of (column, index) to preserve order
protected readonly IDictionary<string, (ColumnExpression column, int index)> myNewColumns =
(ColumnExpressionInterpreter.Evaluate(columnsExpression) ??
protected readonly IDictionary<string, (ColumnExpression column, int index)> myNewColumns;
protected IBlueTableSchema? mySchema;
public ColumnAdder(string columnsExpression) =>
myNewColumns = (ColumnExpressionInterpreter.Evaluate(columnsExpression) ??
throw new Exception("Invalid columnn expression: " + columnsExpression))
.Select((c, i) => (c, i))
.ToDictionary(c => c.c.Name, c => (c.c, c.i));
protected IBlueTableSchema? mySchema;
[MemberNotNull(nameof(mySchema))]
public virtual IBlueRow map(IBlueRow row) {
@@ -1,5 +1,6 @@
using Bts.ColumnSortExpressions;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -30,7 +31,7 @@ public class SortStream : ViewStream {
public SortStream(ViewStream stream, IComparer comparer) {
this.stream = stream;
this.comparer = comparer;
sortCols = [];
sortCols = Array.Empty<ColumnSortExpression>();
}
[MemberNotNull(nameof(sortCols))]
@@ -11,9 +11,9 @@ namespace BCG;
/// Represents an IBlueRowCollection with the rows sorted according to the
/// </summary>
public class SortedTable : IBlueRowCollection {
readonly List<SortRow> rows = [];
readonly Dictionary<int, IBlueRow> rowIndex = [];
readonly IList<ColumnSortExpression> sortCols = [];
readonly List<SortRow> rows = new(0);
readonly Dictionary<int, IBlueRow> rowIndex = new(0);
readonly IList<ColumnSortExpression> sortCols = Array.Empty<ColumnSortExpression>();
readonly IComparer? comparer;
/// <summary>