Skip to content

Commit c2f9458

Browse files
committed
closes #26
1 parent d921254 commit c2f9458

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

src/main/java/com/epam/parso/impl/SasFileConstants.java

+23-16
Original file line numberDiff line numberDiff line change
@@ -497,17 +497,17 @@ interface SasFileConstants {
497497
* The sas7bdat file stores the type of page as a short value with the length of
498498
* {@link SasFileConstants#PAGE_TYPE_LENGTH} bytes and a PAGE_TYPE_OFFSET bytes offset (with addition of
499499
* {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
500-
* There can be {@link SasFileConstants#PAGE_META_TYPE}, {@link SasFileConstants#PAGE_DATA_TYPE}, or
501-
* {@link SasFileConstants#PAGE_MIX_TYPE} page types.
500+
* There can be {@link SasFileConstants#PAGE_META_TYPE_1}, {@link SasFileConstants#PAGE_META_TYPE_2},
501+
* {@link SasFileConstants#PAGE_DATA_TYPE}, or {@link SasFileConstants#PAGE_MIX_TYPE} page types.
502502
*/
503503
long PAGE_TYPE_OFFSET = 0L;
504504

505505
/**
506506
* The sas7bdat file stores the type of page as a short value with the length of PAGE_TYPE_LENGTH bytes
507507
* and a {@link SasFileConstants#PAGE_TYPE_OFFSET} bytes offset (with addition of
508508
* {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
509-
* There can be {@link SasFileConstants#PAGE_META_TYPE}, {@link SasFileConstants#PAGE_DATA_TYPE}, or
510-
* {@link SasFileConstants#PAGE_MIX_TYPE} page types.
509+
* There can be {@link SasFileConstants#PAGE_META_TYPE_1}, {@link SasFileConstants#PAGE_META_TYPE_2},
510+
* {@link SasFileConstants#PAGE_DATA_TYPE}, or {@link SasFileConstants#PAGE_MIX_TYPE} page types.
511511
*/
512512
int PAGE_TYPE_LENGTH = 2;
513513

@@ -528,27 +528,34 @@ interface SasFileConstants {
528528
int BLOCK_COUNT_LENGTH = 2;
529529

530530
/**
531-
* For pages of the {@link SasFileConstants#PAGE_META_TYPE} and {@link SasFileConstants#PAGE_MIX_TYPE} types,
532-
* the sas7bdat file stores the number of subheaders on the current page as a short value - with the length of
533-
* {@link SasFileConstants#SUBHEADER_COUNT_LENGTH} bytes and a SUBHEADER_COUNT_OFFSET bytes offset from
534-
* the beginning of the page (with addition of {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or
535-
* {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
531+
* For pages of the {@link SasFileConstants#PAGE_META_TYPE_1}, {@link SasFileConstants#PAGE_META_TYPE_2}
532+
* and {@link SasFileConstants#PAGE_MIX_TYPE} types, the sas7bdat file stores the number of subheaders on
533+
* the current page as a short value - with the length of {@link SasFileConstants#SUBHEADER_COUNT_LENGTH}
534+
* bytes and a SUBHEADER_COUNT_OFFSET bytes offset from the beginning of the page (with addition of
535+
* {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
536536
*/
537537
long SUBHEADER_COUNT_OFFSET = 4L;
538538

539539
/**
540-
* For pages of the {@link SasFileConstants#PAGE_META_TYPE} and {@link SasFileConstants#PAGE_MIX_TYPE} types,
541-
* the sas7bdat file stores the number of subheaders on the current page as a short value - with the length of
542-
* SUBHEADER_COUNT_LENGTH bytes and a {@link SasFileConstants#SUBHEADER_COUNT_OFFSET} bytes offset from
543-
* the beginning of the page (with addition of {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or
544-
* {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
540+
* For pages of the {@link SasFileConstants#PAGE_META_TYPE_1}, {@link SasFileConstants#PAGE_META_TYPE_2}
541+
* and {@link SasFileConstants#PAGE_MIX_TYPE} types, the sas7bdat file stores the number of subheaders on
542+
* the current page as a short value - with the length of SUBHEADER_COUNT_LENGTH bytes and a
543+
* {@link SasFileConstants#SUBHEADER_COUNT_OFFSET} bytes offset from the beginning of the page
544+
* (with addition of {@link SasFileConstants#PAGE_BIT_OFFSET_X86} or {@link SasFileConstants#PAGE_BIT_OFFSET_X64}).
545545
*/
546546
int SUBHEADER_COUNT_LENGTH = 2;
547547

548548
/**
549-
* The page type storing only metadata as a set of subheaders.
549+
* The page type storing metadata as a set of subheaders. It can also store compressed row data in subheaders.
550+
* The sas7bdat format has two values that correspond to the page type 'meta'.
551+
*/
552+
int PAGE_META_TYPE_1 = 0;
553+
554+
/**
555+
* The page type storing metadata as a set of subheaders. It can also store compressed row data in subheaders.
556+
* The sas7bdat format has two values that correspond to the page type 'meta'.
550557
*/
551-
int PAGE_META_TYPE = 0;
558+
int PAGE_META_TYPE_2 = 16384;
552559

553560
/**
554561
* The page type storing only data as a number of table rows.

src/main/java/com/epam/parso/impl/SasFileParser.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public final class SasFileParser {
150150
*/
151151
private byte[] cachedPage;
152152
/**
153-
* The type of the current page when reading the file. If it is other than {@link SasFileConstants#PAGE_META_TYPE},
153+
* The type of the current page when reading the file. If it is other than
154+
* {@link SasFileConstants#PAGE_META_TYPE_1}, {@link SasFileConstants#PAGE_META_TYPE_1},
154155
* {@link SasFileConstants#PAGE_MIX_TYPE} and {@link SasFileConstants#PAGE_DATA_TYPE} page is skipped.
155156
*/
156157
private int currentPageType;
@@ -344,17 +345,18 @@ private boolean processSasFilePageMeta() throws IOException {
344345
int bitOffset = sasFileProperties.isU64() ? PAGE_BIT_OFFSET_X64 : PAGE_BIT_OFFSET_X86;
345346
readPageHeader();
346347
List<SubheaderPointer> subheaderPointers = new ArrayList<SubheaderPointer>();
347-
if (currentPageType == PAGE_META_TYPE || currentPageType == PAGE_MIX_TYPE) {
348+
if (currentPageType == PAGE_META_TYPE_1 || currentPageType == PAGE_META_TYPE_2
349+
|| currentPageType == PAGE_MIX_TYPE) {
348350
processPageMetadata(bitOffset, subheaderPointers);
349351
}
350352
return currentPageType == PAGE_DATA_TYPE || currentPageType == PAGE_MIX_TYPE
351353
|| currentPageDataSubheaderPointers.size() != 0;
352354
}
353355

354356
/**
355-
* The method to parse and read metadata of a page, used for pages of the {@link SasFileConstants#PAGE_META_TYPE}
356-
* and {@link SasFileConstants#PAGE_MIX_TYPE} types. The method goes through subheaders, one by one, and calls
357-
* the processing functions depending on their signatures.
357+
* The method to parse and read metadata of a page, used for pages of the {@link SasFileConstants#PAGE_META_TYPE_1}
358+
* {@link SasFileConstants#PAGE_META_TYPE_1}, and {@link SasFileConstants#PAGE_MIX_TYPE} types. The method goes
359+
* through subheaders, one by one, and calls the processing functions depending on their signatures.
358360
*
359361
* @param bitOffset the offset from the beginning of the page at which the page stores its metadata.
360362
* @param subheaderPointers the number of subheaders on the page.
@@ -489,7 +491,8 @@ Object[] readNext(List<String> columnNames) throws IOException {
489491
}
490492
int bitOffset = sasFileProperties.isU64() ? PAGE_BIT_OFFSET_X64 : PAGE_BIT_OFFSET_X86;
491493
switch (currentPageType) {
492-
case PAGE_META_TYPE:
494+
case PAGE_META_TYPE_1:
495+
case PAGE_META_TYPE_2:
493496
SubheaderPointer currentSubheaderPointer =
494497
currentPageDataSubheaderPointers.get(currentRowOnPageIndex++);
495498
((ProcessingDataSubheader) subheaderIndexToClass.get(SubheaderIndexes.DATA_SUBHEADER_INDEX))
@@ -529,16 +532,17 @@ Object[] readNext(List<String> columnNames) throws IOException {
529532

530533
/**
531534
* The method to read next page from sas7bdat file and put it into {@link SasFileParser#cachedPage}. If this page
532-
* has {@link SasFileConstants#PAGE_META_TYPE} type method process it's subheaders. Method skips page with type
533-
* other than {@link SasFileConstants#PAGE_META_TYPE}, {@link SasFileConstants#PAGE_MIX_TYPE} or
535+
* has {@link SasFileConstants#PAGE_META_TYPE_1} or {@link SasFileConstants#PAGE_META_TYPE_2} type method process
536+
* it's subheaders. Method skips page with type other than {@link SasFileConstants#PAGE_META_TYPE_1},
537+
* {@link SasFileConstants#PAGE_META_TYPE_2}, {@link SasFileConstants#PAGE_MIX_TYPE} or
534538
* {@link SasFileConstants#PAGE_DATA_TYPE} and reads next.
535539
*
536540
* @throws IOException if reading from the {@link SasFileParser#sasFileStream} stream is impossible.
537541
*/
538542
private void readNextPage() throws IOException {
539543
processNextPage();
540-
while (currentPageType != PAGE_META_TYPE && currentPageType != PAGE_MIX_TYPE
541-
&& currentPageType != PAGE_DATA_TYPE) {
544+
while (currentPageType != PAGE_META_TYPE_1 && currentPageType != PAGE_META_TYPE_2
545+
&& currentPageType != PAGE_MIX_TYPE && currentPageType != PAGE_DATA_TYPE) {
542546
if (eof) {
543547
return;
544548
}
@@ -562,7 +566,8 @@ private void processNextPage() throws IOException {
562566
}
563567

564568
readPageHeader();
565-
if (currentPageType == PAGE_META_TYPE || currentPageType == PAGE_AMD_TYPE) {
569+
if (currentPageType == PAGE_META_TYPE_1 || currentPageType == PAGE_META_TYPE_2
570+
|| currentPageType == PAGE_AMD_TYPE) {
566571
List<SubheaderPointer> subheaderPointers = new ArrayList<SubheaderPointer>();
567572
processPageMetadata(bitOffset, subheaderPointers);
568573
if (currentPageType == PAGE_AMD_TYPE) {

0 commit comments

Comments
 (0)