Skip to content
Browse files

DataPage entity parsing replaced by RecordEntityParser implementations

  • Loading branch information...
1 parent 430501b commit 5e1aa46a8da3557730659578048dc57f84ec7926 @improvedk committed Jan 15, 2012
View
18 src/OrcaMDF.Core/Engine/DataScanner.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using OrcaMDF.Core.Engine.Pages.PFS;
+using OrcaMDF.Core.Engine.Records.Parsers;
using OrcaMDF.Core.MetaData;
using OrcaMDF.Core.MetaData.Enumerations;
@@ -48,12 +49,12 @@ internal IEnumerable<Row> ScanLinkedDataPages(PagePointer loc, Row schema, Compr
{
while (loc != PagePointer.Zero)
{
- var page = Database.GetDataPage(loc, compression);
-
- foreach (var dr in page.GetEntities(schema))
+ var recordParser = RecordEntityParser.CreateEntityParserForPage(loc, compression, Database);
+
+ foreach (var dr in recordParser.GetEntities(schema))
yield return dr;
- loc = page.Header.NextPage;
+ loc = recordParser.NextPage;
}
}
@@ -64,6 +65,7 @@ private IEnumerable<Row> scanTable(string tableName, Row schema)
.Where(x => x.name == tableName)
.Where(x => x.type.Trim() == ObjectType.INTERNAL_TABLE || x.type.Trim() == ObjectType.SYSTEM_TABLE || x.type.Trim() == ObjectType.USER_TABLE)
.SingleOrDefault();
+
if (tableObject == null)
throw new ArgumentException("Table does not exist.");
@@ -150,9 +152,9 @@ private IEnumerable<Row> scanHeap(PagePointer loc, Row schema, CompressionContex
// Loop each header slot and yield the results, provided the header slot is allocated
foreach (var slot in iamPageSlots.Where(x => x != PagePointer.Zero))
{
- var dataPage = Database.GetDataPage(slot, compression);
+ var recordParser = RecordEntityParser.CreateEntityParserForPage(slot, compression, Database);
- foreach (var dr in dataPage.GetEntities(schema))
+ foreach (var dr in recordParser.GetEntities(schema))
yield return dr;
}
@@ -170,9 +172,9 @@ private IEnumerable<Row> scanHeap(PagePointer loc, Row schema, CompressionContex
if(!pfsDescription.IsAllocated)
continue;
- var dataPage = Database.GetDataPage(pageLoc, compression);
+ var recordParser = RecordEntityParser.CreateEntityParserForPage(pageLoc, compression, Database);
- foreach (var dr in dataPage.GetEntities(schema))
+ foreach (var dr in recordParser.GetEntities(schema))
yield return dr;
}
}
View
11 src/OrcaMDF.Core/Engine/Database.cs
@@ -93,6 +93,17 @@ internal PrimaryRecordPage GetPrimaryRecordPage(PagePointer loc, CompressionCont
}
[DebuggerStepThrough]
+ internal CompressedRecordPage GetCompressedRecordPage(PagePointer loc, CompressionContext compression)
+ {
+ if (compression.CompressionLevel == CompressionLevel.None)
+ throw new ArgumentException("Can't load compressed page with a compression level of none.");
+
+ Debug.WriteLine("Loading compressed record page " + loc);
+
+ return new CompressedRecordPage(bufferManager.GetPageBytes(loc.FileID, loc.PageID), compression, this);
+ }
+
+ [DebuggerStepThrough]
internal Page GetPage(PagePointer loc)
{
Debug.WriteLine("Loading Generic Page " + loc);
View
5 src/OrcaMDF.Core/Engine/Records/Parsers/CompressedRecordEntityParser.cs
@@ -18,5 +18,10 @@ internal override IEnumerable<Row> GetEntities(Row schema)
{
throw new NotImplementedException();
}
+
+ internal override PagePointer NextPage
+ {
+ get { return page.Header.NextPage; }
+ }
}
}
View
5 src/OrcaMDF.Core/Engine/Records/Parsers/PrimaryRecordEntityParser.cs
@@ -98,5 +98,10 @@ internal override IEnumerable<Row> GetEntities(Row schema)
yield return dataRow;
}
}
+
+ internal override PagePointer NextPage
+ {
+ get { return page.Header.NextPage; }
+ }
}
}
View
22 src/OrcaMDF.Core/Engine/Records/Parsers/RecordEntityParser.cs
@@ -1,10 +1,30 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using OrcaMDF.Core.MetaData;
namespace OrcaMDF.Core.Engine.Records.Parsers
{
internal abstract class RecordEntityParser
{
internal abstract IEnumerable<Row> GetEntities(Row schema);
+ internal abstract PagePointer NextPage { get; }
+
+ internal static RecordEntityParser CreateEntityParserForPage(PagePointer loc, CompressionContext compression, Database database)
+ {
+ switch (compression.CompressionLevel)
+ {
+ case CompressionLevel.Page:
+ throw new NotImplementedException("Page compression not yet supported.");
+
+ case CompressionLevel.Row:
+ return new CompressedRecordEntityParser(database.GetCompressedRecordPage(loc, compression));
+
+ case CompressionLevel.None:
+ return new PrimaryRecordEntityParser(database.GetPrimaryRecordPage(loc, compression));
+
+ default:
+ throw new ArgumentException("Unsupported compression level: " + compression.CompressionLevel);
+ }
+ }
}
}

0 comments on commit 5e1aa46

Please sign in to comment.
Something went wrong with that request. Please try again.