Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinchoo committed May 28, 2024
1 parent db9dcdc commit 03e14f1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
Binary file modified src/Assets/Db/Northwind.MDF
Binary file not shown.
Binary file modified src/Assets/Db/Northwind_log.ldf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ where comm.Contains(FileHeaderConfiguration.FillChar.Value.ToString())
if (RecordLength <= 0)
{
int maxStartIndex = FixedLengthRecordFieldConfigurations.Max(f => f.StartIndex);
int maxSize = FixedLengthRecordFieldConfigurations.Where(f => f.StartIndex == maxStartIndex).Max(f1 => f1.Size.Value);
var fc = FixedLengthRecordFieldConfigurations.Where(f => f.StartIndex == maxStartIndex && f.Size.Value == maxSize).FirstOrDefault();
int maxSize = FixedLengthRecordFieldConfigurations.Any(f => f.StartIndex == maxStartIndex && f.Size != null) ? FixedLengthRecordFieldConfigurations.Where(f => f.StartIndex == maxStartIndex && f.Size != null).Max(f1 => f1.Size.Value) : 0;
var fc = FixedLengthRecordFieldConfigurations.Where(f => f.StartIndex == maxStartIndex && f.Size != null && f.Size.Value == maxSize).FirstOrDefault();
if (fc != null)
{
RecordLength = fc.StartIndex + fc.Size.Value;
Expand Down
11 changes: 9 additions & 2 deletions src/ChoETL/File/FixedLength/ChoFixedLengthWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void Write(IDataReader dr)

Configuration.UseNestedKeyFormat = false;

int startIndex = 0;
if (Configuration.FixedLengthRecordFieldConfigurations.IsNullOrEmpty())
{
string colName = null;
Expand All @@ -171,7 +172,9 @@ public void Write(IDataReader dr)
colType = row["DataType"] as Type;
//if (!colType.IsSimple()) continue;

Configuration.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration(colName) { FieldType = colType });
var size = ChoFixedLengthFieldDefaultSizeConfiguation.Instance.GetSize(colType);
Configuration.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration(colName) { FieldType = colType, StartIndex = startIndex, Size = size });
startIndex += size;
}
}

Expand Down Expand Up @@ -202,6 +205,7 @@ public void Write(DataTable dt)
DataTable schemaTable = dt;

int ordinal = 0;
int startIndex = 0;
if (Configuration.FixedLengthRecordFieldConfigurations.IsNullOrEmpty())
{
string colName = null;
Expand All @@ -212,7 +216,10 @@ public void Write(DataTable dt)
colType = col.DataType;
//if (!colType.IsSimple()) continue;

Configuration.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration(colName) { FieldType = colType });
var size = ChoFixedLengthFieldDefaultSizeConfiguation.Instance.GetSize(colType);

Configuration.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration(colName) { FieldType = colType, StartIndex = startIndex, Size = size });
startIndex += size;
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/Test/ChoFixedLengthWriterTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void Main(string[] args)
{
ChoETLFrxBootstrap.TraceLevel = System.Diagnostics.TraceLevel.Off;

POCOTest();
WriteDataReaderTest();
}

[SetUp]
Expand All @@ -36,9 +36,9 @@ public void Setup()
[Test]
public static void WriteDataTableTest()
{
string expected = @"Id,Name
1,Tom
2,Mark";
string expected = @"Id Name
0000000001Tom
0000000002Mark ";

DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
Expand All @@ -59,9 +59,9 @@ public static void WriteDataTableTest()
[Test]
public static void WriteDataReaderTest()
{
string expected = @"Id,Name
1,Tom
2,Mark";
string expected = @"Id Name
0000000001Tom
0000000002Mark ";

DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
Expand Down
12 changes: 6 additions & 6 deletions src/Test/ChoParquetWriterTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,14 +1572,14 @@ public static void POCOTreatDateTimeAsDateTimeOffsetTestWith_NO_Converter()
""Price"": null,
""Quantity"": ""2"",
""Name"": null,
""CreateDate"": ""0001-01-01T12:00:00+00:00""
""CreateDate"": null
},
{
""Id"": ""100"",
""Price"": null,
""Quantity"": null,
""Name"": null,
""CreateDate"": ""0001-01-01T12:00:00+00:00""
""CreateDate"": null
},
{
""Id"": null,
Expand Down Expand Up @@ -2544,8 +2544,8 @@ private static DataTable GenerateDataTableWithNullableValueTypes()
dt.Columns.Add("JoinedDate", typeof(DateTime));


dt.Rows.Add(1, 100, 100000.10, DateTime.Now);
dt.Rows.Add(2, 200, 200000.10, DateTime.Now.AddDays(-1));
dt.Rows.Add(1, 100, 100000.10, _currentDateTime);
dt.Rows.Add(2, 200, 200000.10, _currentDateTime.AddDays(-1));
dt.Rows.Add(DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value);

return dt;
Expand All @@ -2559,8 +2559,8 @@ public static void GenParquetFileWithNullableValueTypeDataTable()
string filePath = "GenParquetFileWithNullableValueTypeDataTable.parquet";

string expected = @"Id,MgrId,Salary,JoinedDate
1,100,100000.1,4/21/2024
2,200,200000.1,4/20/2024
1,100,100000.1,6/10/2023
2,200,200000.1,6/9/2023
,,,";


Expand Down

0 comments on commit 03e14f1

Please sign in to comment.