simplify error checking

This commit is contained in:
Colin Dellow 2018-07-05 22:09:22 -04:00
parent e83a21db15
commit a52ad9c20c
1 changed files with 21 additions and 40 deletions

View File

@ -809,46 +809,36 @@ void ParquetCursor::ensureColumn(int col) {
colRows[col] = rowId; colRows[col] = rowId;
wasNull = false; wasNull = false;
bool hadValue = false;
switch(types[col]) { switch(types[col]) {
case parquet::Type::INT32: case parquet::Type::INT32:
{ {
parquet::Int32Scanner* s = (parquet::Int32Scanner*)scanners[col].get(); parquet::Int32Scanner* s = (parquet::Int32Scanner*)scanners[col].get();
int rv = 0; int rv = 0;
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colIntValues[col] = rv; colIntValues[col] = rv;
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::FLOAT: case parquet::Type::FLOAT:
{ {
parquet::FloatScanner* s = (parquet::FloatScanner*)scanners[col].get(); parquet::FloatScanner* s = (parquet::FloatScanner*)scanners[col].get();
float rv = 0; float rv = 0;
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colDoubleValues[col] = rv; colDoubleValues[col] = rv;
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::DOUBLE: case parquet::Type::DOUBLE:
{ {
parquet::DoubleScanner* s = (parquet::DoubleScanner*)scanners[col].get(); parquet::DoubleScanner* s = (parquet::DoubleScanner*)scanners[col].get();
double rv = 0; double rv = 0;
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colDoubleValues[col] = rv; colDoubleValues[col] = rv;
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::BYTE_ARRAY: case parquet::Type::BYTE_ARRAY:
{ {
parquet::ByteArrayScanner* s = (parquet::ByteArrayScanner*)scanners[col].get(); parquet::ByteArrayScanner* s = (parquet::ByteArrayScanner*)scanners[col].get();
if(!s->NextValue(&colByteArrayValues[col], &wasNull)) { hadValue = s->NextValue(&colByteArrayValues[col], &wasNull);
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::INT96: case parquet::Type::INT96:
@ -862,22 +852,16 @@ void ParquetCursor::ensureColumn(int col) {
// (julian_day - 2440588) * (86400 * 1000 * 1000 * 1000) + nanoseconds // (julian_day - 2440588) * (86400 * 1000 * 1000 * 1000) + nanoseconds
parquet::Int96Scanner* s = (parquet::Int96Scanner*)scanners[col].get(); parquet::Int96Scanner* s = (parquet::Int96Scanner*)scanners[col].get();
parquet::Int96 rv {0, 0, 0}; parquet::Int96 rv {0, 0, 0};
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colIntValues[col] = int96toMsSinceEpoch(rv); colIntValues[col] = int96toMsSinceEpoch(rv);
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::INT64: case parquet::Type::INT64:
{ {
parquet::Int64Scanner* s = (parquet::Int64Scanner*)scanners[col].get(); parquet::Int64Scanner* s = (parquet::Int64Scanner*)scanners[col].get();
long rv = 0; long rv = 0;
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colIntValues[col] = rv; colIntValues[col] = rv;
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
@ -885,24 +869,18 @@ void ParquetCursor::ensureColumn(int col) {
{ {
parquet::BoolScanner* s = (parquet::BoolScanner*)scanners[col].get(); parquet::BoolScanner* s = (parquet::BoolScanner*)scanners[col].get();
bool rv = false; bool rv = false;
if(s->NextValue(&rv, &wasNull)) { hadValue = s->NextValue(&rv, &wasNull);
colIntValues[col] = rv ? 1 : 0; colIntValues[col] = rv ? 1 : 0;
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
case parquet::Type::FIXED_LEN_BYTE_ARRAY: case parquet::Type::FIXED_LEN_BYTE_ARRAY:
{ {
parquet::FixedLenByteArrayScanner* s = (parquet::FixedLenByteArrayScanner*)scanners[col].get(); parquet::FixedLenByteArrayScanner* s = (parquet::FixedLenByteArrayScanner*)scanners[col].get();
parquet::FixedLenByteArray flba; parquet::FixedLenByteArray flba;
if(s->NextValue(&flba, &wasNull)) { hadValue = s->NextValue(&flba, &wasNull);
colByteArrayValues[col].ptr = flba.ptr; colByteArrayValues[col].ptr = flba.ptr;
// TODO: cache this // TODO: cache this
colByteArrayValues[col].len = rowGroupMetadata->schema()->Column(col)->type_length(); colByteArrayValues[col].len = rowGroupMetadata->schema()->Column(col)->type_length();
} else {
throw std::invalid_argument("unexpectedly lacking a next value");
}
break; break;
} }
default: default:
@ -915,6 +893,9 @@ void ParquetCursor::ensureColumn(int col) {
break; break;
} }
if(!hadValue)
throw std::invalid_argument("unexpectedly lacking a next value");
colNulls[col] = wasNull; colNulls[col] = wasNull;
} }
} }