std::unique_ptr TypeImpl::createRowBatch()

in c++/src/TypeImpl.cc [285:387]


  std::unique_ptr<ColumnVectorBatch> TypeImpl::createRowBatch(uint64_t capacity,
                                                              MemoryPool& memoryPool, bool encoded,
                                                              bool useTightNumericVector) const {
    switch (static_cast<int64_t>(kind_)) {
      case BOOLEAN:
        if (useTightNumericVector) {
          return std::make_unique<ByteVectorBatch>(capacity, memoryPool);
        }
        return std::make_unique<LongVectorBatch>(capacity, memoryPool);
      case BYTE:
        if (useTightNumericVector) {
          return std::make_unique<ByteVectorBatch>(capacity, memoryPool);
        }
        return std::make_unique<LongVectorBatch>(capacity, memoryPool);
      case SHORT:
        if (useTightNumericVector) {
          return std::make_unique<ShortVectorBatch>(capacity, memoryPool);
        }
        return std::make_unique<LongVectorBatch>(capacity, memoryPool);
      case INT:
        if (useTightNumericVector) {
          return std::make_unique<IntVectorBatch>(capacity, memoryPool);
        }
        return std::make_unique<LongVectorBatch>(capacity, memoryPool);
      case LONG:
      case DATE:
        return std::make_unique<LongVectorBatch>(capacity, memoryPool);

      case FLOAT:
        if (useTightNumericVector) {
          return std::make_unique<FloatVectorBatch>(capacity, memoryPool);
        }
        return std::make_unique<DoubleVectorBatch>(capacity, memoryPool);
      case DOUBLE:
        return std::make_unique<DoubleVectorBatch>(capacity, memoryPool);

      case STRING:
      case BINARY:
      case CHAR:
      case VARCHAR:
        return encoded ? std::make_unique<EncodedStringVectorBatch>(capacity, memoryPool)
                       : std::make_unique<StringVectorBatch>(capacity, memoryPool);

      case TIMESTAMP:
      case TIMESTAMP_INSTANT:
        return std::make_unique<TimestampVectorBatch>(capacity, memoryPool);

      case STRUCT: {
        auto result = std::make_unique<StructVectorBatch>(capacity, memoryPool);
        for (uint64_t i = 0; i < getSubtypeCount(); ++i) {
          result->fields.push_back(
              getSubtype(i)
                  ->createRowBatch(capacity, memoryPool, encoded, useTightNumericVector)
                  .release());
        }
        return result;
      }

      case LIST: {
        auto result = std::make_unique<ListVectorBatch>(capacity, memoryPool);
        if (getSubtype(0) != nullptr) {
          result->elements =
              getSubtype(0)->createRowBatch(capacity, memoryPool, encoded, useTightNumericVector);
        }
        return result;
      }

      case MAP: {
        auto result = std::make_unique<MapVectorBatch>(capacity, memoryPool);
        if (getSubtype(0) != nullptr) {
          result->keys =
              getSubtype(0)->createRowBatch(capacity, memoryPool, encoded, useTightNumericVector);
        }
        if (getSubtype(1) != nullptr) {
          result->elements =
              getSubtype(1)->createRowBatch(capacity, memoryPool, encoded, useTightNumericVector);
        }
        return result;
      }

      case DECIMAL: {
        if (getPrecision() == 0 || getPrecision() > 18) {
          return std::make_unique<Decimal128VectorBatch>(capacity, memoryPool);
        } else {
          return std::make_unique<Decimal64VectorBatch>(capacity, memoryPool);
        }
      }

      case UNION: {
        auto result = std::make_unique<UnionVectorBatch>(capacity, memoryPool);
        for (uint64_t i = 0; i < getSubtypeCount(); ++i) {
          result->children.push_back(
              getSubtype(i)
                  ->createRowBatch(capacity, memoryPool, encoded, useTightNumericVector)
                  .release());
        }
        return result;
      }

      default:
        throw NotImplementedYet("not supported yet");
    }
  }