uint64_t JoinPartition::writeByteStream(int which, ByteStream &bs) { size_t &offset = (which == 0 ? nextSmallOffset : nextLargeOffset); fstream &fs = (which == 0 ? smallFile : largeFile); const char *filename = (which == 0 ? smallFilename.c_str() : largeFilename.c_str()); fs.open(filename, ios::binary | ios::out | ios::app); int saveErrno = errno; if (!fs) { fs.close(); ostringstream os; os << "Disk join could not open file (write access) " << filename << ": " << strerror(saveErrno) << endl; throw IDBExcept(os.str().c_str(), ERR_DBJ_FILE_IO_ERROR); } uint64_t ret = 0; size_t len = bs.length(); idbassert(len != 0); fs.seekp(offset); if (!useCompression) { ret = len + 4; fs.write((char *) &len, sizeof(len)); fs.write((char *) bs.buf(), len); saveErrno = errno; if (!fs) { fs.close(); ostringstream os; os << "Disk join could not write file " << filename << ": " << strerror(saveErrno) << endl; throw IDBExcept(os.str().c_str(), ERR_DBJ_FILE_IO_ERROR); } totalBytesWritten += sizeof(len) + len; } else { uint64_t maxSize = compressor.maxCompressedSize(len); size_t actualSize; boost::scoped_array<uint8_t> compressed(new uint8_t[maxSize]); compressor.compress((char *) bs.buf(), len, (char *) compressed.get(), &actualSize); ret = actualSize + 4; fs.write((char *) &actualSize, sizeof(actualSize)); fs.write((char *) compressed.get(), actualSize); saveErrno = errno; if (!fs) { fs.close(); ostringstream os; os << "Disk join could not write file " << filename << ": " << strerror(saveErrno) << endl; throw IDBExcept(os.str().c_str(), ERR_DBJ_FILE_IO_ERROR); } totalBytesWritten += sizeof(actualSize) + actualSize; } bs.advance(len); offset = fs.tellp(); fs.close(); return ret; }
void ColumnCommand::createCommand(ByteStream& bs) { uint8_t tmp8; bs.advance(1); bs >> tmp8; _isScan = tmp8; bs >> traceFlags; bs >> filterString; #if 0 cout << "filter string: "; for (uint32_t i = 0; i < filterString.length(); ++i) cout << (int) filterString.buf()[i] << " "; cout << endl; #endif bs >> tmp8; colType.colDataType = (execplan::CalpontSystemCatalog::ColDataType) tmp8; bs >> tmp8; colType.colWidth = tmp8; bs >> tmp8; colType.scale = tmp8; bs >> tmp8; colType.compressionType = tmp8; bs >> BOP; bs >> filterCount; deserializeInlineVector(bs, lastLbid); // cout << "lastLbid count=" << lastLbid.size() << endl; // for (uint32_t i = 0; i < lastLbid.size(); i++) // cout << " " << lastLbid[i]; //cout << "CreateCommand() o:" << getOID() << " lastLbid: " << lastLbid << endl; Command::createCommand(bs); parsedColumnFilter = primitives::parseColumnFilter(filterString.buf(), colType.colWidth, colType.colDataType, filterCount, BOP); /* OR hack */ emptyFilter = primitives::parseColumnFilter(filterString.buf(), colType.colWidth, colType.colDataType, 0, BOP); /* XXXPAT: for debugging only */ // bs >> colType.columnOID; // cout << "got filterCount " << filterCount << endl; // cout << "made a ColumnCommand OID = " << OID << endl; }