Skip to content

Commit

Permalink
added tests for all table loads
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyshazam committed Feb 8, 2024
1 parent 771ebd8 commit d827c10
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ tests/data/checkpoints_with_expired_logs/
tests/data/read_null_partitions_from_checkpoint/
tests/data/action_reconciliation/
tests/data/simple_table_with_no_checkpoint/
tests/data/simple_table_with_no_checkpoint_2/
tests/data/simple_table_with_no_checkpoint_2/
.DS_Store
2 changes: 0 additions & 2 deletions tests/DeltaLake.Tests/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;

namespace DeltaLake.Tests
{
public static class Settings
Expand Down
14 changes: 14 additions & 0 deletions tests/DeltaLake.Tests/Table/AllTablesEnumerable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections;

namespace DeltaLake.Tests.Table;
public partial class LoadTests
{
public class AllTablesEnumerable : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator() => TableHelpers.ValidTables.Select(x => new object[] {
x
}).GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
108 changes: 108 additions & 0 deletions tests/DeltaLake.Tests/Table/LoadTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using DeltaLake.Runtime;
using DeltaLake.Table;

namespace DeltaLake.Tests.Table;
public partial class LoadTests
{
public static TableIdentifier[] AllTables = TableHelpers.Tables.Keys.ToArray();

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task Load_Table_At_Version_Test(long version)
{
var location = TableIdentifier.SimpleTable.TablePath();
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions
{
Version = version,
},
CancellationToken.None);
Assert.Equal(version, table.Version());
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task Table_Load_Version_Test(long version)
{
var location = TableIdentifier.SimpleTable.TablePath();
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions(),
CancellationToken.None);
Assert.Equal(4, table.Version());
await table.LoadVersionAsync(version, CancellationToken.None);
Assert.Equal(version, table.Version());
}


[Fact]
public async Task Table_Load_At_Now()
{
var dateTimeOffset = DateTimeOffset.UtcNow;
var location = TableIdentifier.SimpleTable.TablePath();
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions
{
Version = 1,
},
CancellationToken.None);
Assert.Equal(1, table.Version());
await table.LoadDateTimeAsync(dateTimeOffset, CancellationToken.None);
Assert.Equal(4, table.Version());
}

[Theory]
[InlineData(TableIdentifier.Checkpoints, 1, 12)]
[InlineData(TableIdentifier.CheckpointsVacuumed, 5, 12)]
[InlineData(TableIdentifier.Delta020, 1, 3)]
public async Task Table_Load_Latest(TableIdentifier identifier, int minVersion, int expectedVersion)
{
var location = identifier.TablePath();
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions
{
Version = minVersion,
},
CancellationToken.None);
Assert.Equal(minVersion, table.Version());
await table.LoadDateTimeAsync(DateTimeOffset.UtcNow, CancellationToken.None);
Assert.Equal(expectedVersion, table.Version());
}

[Theory]
[ClassData(typeof(AllTablesEnumerable))]
public async Task Table_Will_Load_Test(TableIdentifier identifier)
{
var location = identifier.TablePath();
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions(),
CancellationToken.None);
switch (identifier)
{
case TableIdentifier.Covid19NYT:
case TableIdentifier.Delta220PartitionedTypes:
case TableIdentifier.SimpleCommit:
case TableIdentifier.Delta08NumericPartition:
case TableIdentifier.Delta08Date:
case TableIdentifier.Golden:
case TableIdentifier.ConcurrentWorkers:
case TableIdentifier.Delta08NullPartition:
case TableIdentifier.Delta08Partition:
case TableIdentifier.Delta08SpecialPartition:
case TableIdentifier.TableWithColumnMapping:
case TableIdentifier.TableWithEdgeTimestamps:
case TableIdentifier.TableWithLiquidClustering:
case TableIdentifier.TableWithoutDvSmall:
Assert.Equal(0, table.Version());
break;
default:
Assert.NotEqual(0, table.Version());
break;
}
}
}
91 changes: 91 additions & 0 deletions tests/DeltaLake.Tests/Table/TableHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
namespace DeltaLake.Tests.Table;

public enum TableIdentifier
{
CheckpointWithPartitions,
Checkpoints,
CheckpointsTombstones,
CheckpointsVacuumed,
ConcurrentWorkers,
Covid19NYT,
Delta020,
Delta08Empty,
Delta08,
Delta08Date,
Delta08NullPartition,
Delta08NumericPartition,
Delta08Partition,
Delta08SpecialPartition,
Delta121OnlyStructStats,
Delta220PartitionedTypes,
DeltaLiveTable,
Golden,
HttpRequests,
Issue1374,
SimpleCommit,
SimpleTable,
SimpleTableFeatures,
SimpleTableWithCdc,
SimpleTableWithCheckPoint,
TableWithColumnMapping,
TableWithDeletionLogs,
TableWithEdgeTimestamps,
TableWithLiquidClustering,
TableWithDvSmall,
TableWithoutDvSmall,
WithCheckpointNoLastcheckpoint,
}
public static class TableHelpers
{
public static readonly IReadOnlyDictionary<TableIdentifier, string> Tables = new Dictionary<TableIdentifier, string>
{
[TableIdentifier.CheckpointWithPartitions] = "checkpoint_with_partitions",
[TableIdentifier.Checkpoints] = "checkpoints",
[TableIdentifier.CheckpointsTombstones] = "checkpoints_tombstones",
[TableIdentifier.CheckpointsVacuumed] = "checkpoints_vacuumed",
[TableIdentifier.ConcurrentWorkers] = "concurrent_workers",
[TableIdentifier.Covid19NYT] = "COVID-19_NYT",
[TableIdentifier.Delta020] = "delta-0.2.0",
[TableIdentifier.Delta08Empty] = "delta-0.8-empty",
[TableIdentifier.Delta08] = "delta-0.8.0",
[TableIdentifier.Delta08Date] = "delta-0.8.0-date",
[TableIdentifier.Delta08NullPartition] = "delta-0.8.0-null-partition",
[TableIdentifier.Delta08NumericPartition] = "delta-0.8.0-numeric-partition",
[TableIdentifier.Delta08Partition] = "delta-0.8.0-partitioned",
[TableIdentifier.Delta08SpecialPartition] = "delta-0.8.0-special-partition",
[TableIdentifier.Delta121OnlyStructStats] = "delta-1.2.1-only-struct-stats",
[TableIdentifier.Delta220PartitionedTypes] = "delta-2.2.0-partitioned-types",
[TableIdentifier.DeltaLiveTable] = "delta-live-table",
[TableIdentifier.Golden] = Path.Join("golden", "data-reader-array-primitives"),
[TableIdentifier.HttpRequests] = "http_requests",
[TableIdentifier.Issue1374] = "issue_1374",
[TableIdentifier.SimpleCommit] = "simple_commit",
[TableIdentifier.SimpleTable] = "simple_table",
[TableIdentifier.SimpleTableFeatures] = "simple_table_features",
[TableIdentifier.SimpleTableWithCdc] = "simple_table_with_cdc",
[TableIdentifier.SimpleTableWithCheckPoint] = "simple_table_with_checkpoint",
[TableIdentifier.TableWithColumnMapping] = "table_with_column_mapping",
[TableIdentifier.TableWithDeletionLogs] = "table_with_deletion_logs",
[TableIdentifier.TableWithEdgeTimestamps] = "table_with_edge_timestamps",
[TableIdentifier.TableWithLiquidClustering] = "table_with_liquid_clustering",
[TableIdentifier.TableWithDvSmall] = "table-with-dv-small",
[TableIdentifier.TableWithoutDvSmall] = "table-without-dv-small",
[TableIdentifier.WithCheckpointNoLastcheckpoint] = "with_checkpoint_no_last_checkpoint",
};

public static IEnumerable<TableIdentifier> ValidTables => Tables.Keys.Where(t => t switch
{
TableIdentifier.CheckpointsTombstones => false,
_ => true,
});

public static string LogPath(this TableIdentifier tid, string? pathRoot = null)
{
return Path.Join(pathRoot ?? Settings.TestRoot, Tables[tid], "_delta_log");
}

public static string TablePath(this TableIdentifier tid, string? pathRoot = null)
{
return Path.Join(pathRoot ?? Settings.TestRoot, Tables[tid]);
}
}
38 changes: 0 additions & 38 deletions tests/DeltaLake.Tests/Table/TableTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Apache.Arrow;
using Apache.Arrow.Memory;
using Apache.Arrow.Types;
Expand Down Expand Up @@ -65,39 +60,6 @@ public async Task Load_Table_Memory_Test()
Assert.Equal(4, table.Version());
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task Load_Table_At_Version_Test(long version)
{
var location = Path.Join(Settings.TestRoot, "simple_table");
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions
{
Version = version,
},
CancellationToken.None);
Assert.Equal(version, table.Version());
}

[Theory]
[InlineData(1)]
[InlineData(2)]
[InlineData(3)]
[InlineData(4)]
public async Task Table_Load_Version_Test(long version)
{
var location = Path.Join(Settings.TestRoot, "simple_table");
using var runtime = new DeltaRuntime(RuntimeOptions.Default);
using var table = await DeltaTable.LoadAsync(runtime, location, new TableOptions(),
CancellationToken.None);
Assert.Equal(4, table.Version());
await table.LoadVersionAsync(version, CancellationToken.None);
Assert.Equal(version, table.Version());
}

[Fact]
public async Task Table_Insert_Test()
{
Expand Down
4 changes: 4 additions & 0 deletions tests/DeltaLake.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"longRunningTestSeconds": 60
}

0 comments on commit d827c10

Please sign in to comment.