示例#1
0
void Database::UpdateStatsWithOid(const oid_t table_oid) const {
  LOG_INFO("Update table(%lu)'s stats in Database(%lu)", table_oid,
           database_oid);

  auto table = GetTableWithOid(table_oid);
  bridge::Bridge::SetNumberOfTuples(table_oid, table->GetNumberOfTuples());

  for (oid_t index_offset = 0; index_offset < table->GetIndexCount();
      index_offset++) {
    auto index = table->GetIndex(index_offset);
    bridge::Bridge::SetNumberOfTuples(index->GetOid(),
                                      index->GetNumberOfTuples());
  }
}
示例#2
0
TEST_F(LoggingTests, BasicDeleteTest) {
  auto recovery_table = ExecutorTestsUtil::CreateTable(1024);
  auto &manager = catalog::Manager::GetInstance();
  storage::Database db(DEFAULT_DB_ID);
  manager.AddDatabase(&db);
  db.AddTable(recovery_table);

  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 0);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 1);
  logging::WriteAheadFrontendLogger fel(true);

  cid_t test_commit_id = 10;

  auto curr_rec = new logging::TupleRecord(
      LOGRECORD_TYPE_TUPLE_UPDATE, test_commit_id, recovery_table->GetOid(),
      INVALID_ITEMPOINTER, ItemPointer(100, 4), nullptr, DEFAULT_DB_ID);
  fel.DeleteTuple(curr_rec);

  delete curr_rec;

  auto tg_header = recovery_table->GetTileGroupById(100)->GetHeader();
  EXPECT_EQ(tg_header->GetEndCommitId(4), test_commit_id);

  //  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 1);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 2);
}
示例#3
0
TEST_F(DEMImageNormals_test, NormalsAreNormalized)
{
    auto demNormalFilter = vtkSmartPointer<DEMImageNormals>::New();
    demNormalFilter->SetCoordinatesUnitScale(1.0);
    demNormalFilter->SetElevationUnitScale(1.0);
    demNormalFilter->SetInputData(dem);
    ASSERT_TRUE(demNormalFilter->GetExecutive()->Update());
    auto normals = demNormalFilter->GetOutput()->GetPointData()->GetNormals();
    ASSERT_TRUE(normals);
    ASSERT_EQ(dem->GetNumberOfPoints(), normals->GetNumberOfTuples());

    for (vtkIdType i = 0; i < normals->GetNumberOfTuples(); ++i)
    {
        vtkVector3d normal;
        normals->GetTuple(i, normal.GetData());
        ASSERT_FLOAT_EQ(1.f, static_cast<float>(normal.Norm()));
    }
}
示例#4
0
TEST_F(LoggingTests, BasicUpdateTest) {
  auto recovery_table = ExecutorTestsUtil::CreateTable(1024);
  auto &manager = catalog::Manager::GetInstance();
  storage::Database db(DEFAULT_DB_ID);
  manager.AddDatabase(&db);
  db.AddTable(recovery_table);

  auto tuples = BuildLoggingTuples(recovery_table, 1, false, false);
  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 0);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 1);
  EXPECT_EQ(tuples.size(), 1);
  logging::WriteAheadFrontendLogger fel(true);
  //  auto bel = logging::WriteAheadBackendLogger::GetInstance();
  cid_t test_commit_id = 10;

  Value val0 = tuples[0]->GetValue(0);
  Value val1 = tuples[0]->GetValue(1);
  Value val2 = tuples[0]->GetValue(2);
  Value val3 = tuples[0]->GetValue(3);

  auto curr_rec = new logging::TupleRecord(
      LOGRECORD_TYPE_TUPLE_UPDATE, test_commit_id, recovery_table->GetOid(),
      ItemPointer(100, 5), ItemPointer(100, 4), tuples[0], DEFAULT_DB_ID);
  curr_rec->SetTuple(tuples[0]);
  fel.UpdateTuple(curr_rec);
  delete curr_rec;

  auto tg_header = recovery_table->GetTileGroupById(100)->GetHeader();
  EXPECT_TRUE(tg_header->GetBeginCommitId(5) <= test_commit_id);
  EXPECT_EQ(tg_header->GetEndCommitId(5), MAX_CID);
  EXPECT_EQ(tg_header->GetEndCommitId(4), test_commit_id);

  EXPECT_TRUE(
      val0.Compare(recovery_table->GetTileGroupById(100)->GetValue(5, 0)) == 0);
  EXPECT_TRUE(
      val1.Compare(recovery_table->GetTileGroupById(100)->GetValue(5, 1)) == 0);
  EXPECT_TRUE(
      val2.Compare(recovery_table->GetTileGroupById(100)->GetValue(5, 2)) == 0);
  EXPECT_TRUE(
      val3.Compare(recovery_table->GetTileGroupById(100)->GetValue(5, 3)) == 0);

  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 0);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 2);
}
示例#5
0
TEST_F(ArrayChangeInformationFilter_test, vtkAssignAttribute_CorrectNumberOfComponentsPassedDownstream)
{
    inAttr->SetNumberOfComponents(3);
    inAttr->SetNumberOfTuples(17);
    for (vtkIdType i = 0; i < inAttr->GetNumberOfValues(); ++i)
    {
        inAttr->SetValue(i, static_cast<float>(i));
    }
    auto inImage = vtkSmartPointer<vtkImageData>::New();
    inImage->GetPointData()->SetScalars(inAttr);
    inImage->SetExtent(0, 0, 2, 18, 3, 3);

    auto infoSource = vtkSmartPointer<InformationSource>::New();
    infoSource->SetOutput(inImage);

    vtkDataObject::SetActiveAttributeInfo(infoSource->GetOutInfo(),
        vtkDataObject::FIELD_ASSOCIATION_POINTS,
        vtkDataSetAttributes::SCALARS,
        inAttr->GetName(),
        inAttr->GetDataType(),
        inAttr->GetNumberOfComponents(),
        static_cast<int>(inAttr->GetNumberOfTuples()));

    filter->SetAttributeLocation(ArrayChangeInformationFilter::POINT_DATA);
    filter->SetAttributeType(vtkDataSetAttributes::SCALARS);
    filter->SetInputConnection(infoSource->GetOutputPort());
    filter->EnableRenameOff();
    filter->EnableSetUnitOff();

    auto assignToVectors = vtkSmartPointer<vtkAssignAttribute>::New();
    assignToVectors->SetInputConnection(filter->GetOutputPort());
    assignToVectors->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS,
        vtkAssignAttribute::POINT_DATA);

    auto reassignScalars = vtkSmartPointer<vtkAssignAttribute>::New();
    reassignScalars->SetInputConnection(assignToVectors->GetOutputPort());
    reassignScalars->Assign(vtkDataSetAttributes::VECTORS, vtkDataSetAttributes::SCALARS,
        vtkAssignAttribute::POINT_DATA);

    auto normalize = vtkSmartPointer<vtkImageNormalize>::New();
    normalize->SetInputConnection(reassignScalars->GetOutputPort());
    normalize->SetEnableSMP(false);
    normalize->SetNumberOfThreads(1);

    // before patching (VTK 7.1+) vtkAssignAttribute, this would cause segmentation faults
    normalize->Update();
    auto outImg = normalize->GetOutput();
    auto outScalars = outImg->GetPointData()->GetScalars();

    ASSERT_EQ(inAttr->GetNumberOfComponents(), outScalars->GetNumberOfComponents());
    ASSERT_EQ(inAttr->GetNumberOfTuples(), outScalars->GetNumberOfTuples());
}
示例#6
0
int AssignPointAttributeToCoordinatesFilter::RequestData(
    vtkInformation * /*request*/,
    vtkInformationVector ** inputVector,
    vtkInformationVector * outputVector)
{
    auto inData = vtkPointSet::SafeDownCast(inputVector[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));
    auto outData = vtkPointSet::SafeDownCast(outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT()));

    auto previousPointCoords = inData->GetPoints()->GetData();
    vtkDataArray * pointsToAssign = nullptr;

    if (!this->AttributeArrayToAssign.empty())
    {
        auto newPoints = inData->GetPointData()->GetArray(this->AttributeArrayToAssign.c_str());
        if (!newPoints)
        {
            vtkErrorMacro("Array to assign not found in input data: " + this->AttributeArrayToAssign);
            return 0;
        }

        if (newPoints->GetNumberOfComponents() != 3
            || newPoints->GetNumberOfTuples() != inData->GetNumberOfPoints())
        {
            vtkErrorMacro("Component/Tuple count mismatching in selected data array: " + this->AttributeArrayToAssign);
            return 0;
        }
        pointsToAssign = newPoints;
    }

    outData->ShallowCopy(inData);

    if (pointsToAssign)
    {
        vtkNew<vtkPoints> newPoints;
        newPoints->SetData(pointsToAssign);
        outData->SetPoints(newPoints.Get());
    }

    // pass current point coordinates as point attribute
    if (previousPointCoords)
    {
        outData->GetPointData()->AddArray(previousPointCoords);
    }

    if (auto currentCoords = pointsToAssign ? pointsToAssign : previousPointCoords)
    {
        outData->GetPointData()->SetActiveScalars(currentCoords->GetName());
    }

    return 1;
}
示例#7
0
TEST_F(LoggingTests, OutOfOrderCommitTest) {
  auto recovery_table = ExecutorTestsUtil::CreateTable(1024);
  auto &manager = catalog::Manager::GetInstance();
  storage::Database db(DEFAULT_DB_ID);
  manager.AddDatabase(&db);
  db.AddTable(recovery_table);

  auto tuples = BuildLoggingTuples(recovery_table, 1, false, false);
  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 0);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 1);
  EXPECT_EQ(tuples.size(), 1);
  logging::WriteAheadFrontendLogger fel(true);
  //  auto bel = logging::WriteAheadBackendLogger::GetInstance();
  cid_t test_commit_id = 10;

  auto curr_rec = new logging::TupleRecord(
      LOGRECORD_TYPE_TUPLE_UPDATE, test_commit_id + 1, recovery_table->GetOid(),
      INVALID_ITEMPOINTER, ItemPointer(100, 5), nullptr, DEFAULT_DB_ID);
  fel.DeleteTuple(curr_rec);
  delete curr_rec;

  EXPECT_EQ(recovery_table->GetTileGroupCount(), 2);

  curr_rec = new logging::TupleRecord(
      LOGRECORD_TYPE_TUPLE_INSERT, test_commit_id, recovery_table->GetOid(),
      ItemPointer(100, 5), INVALID_ITEMPOINTER, tuples[0], DEFAULT_DB_ID);

  curr_rec->SetTuple(tuples[0]);
  fel.InsertTuple(curr_rec);

  delete curr_rec;

  auto tg_header = recovery_table->GetTileGroupById(100)->GetHeader();
  EXPECT_EQ(tg_header->GetEndCommitId(5), test_commit_id + 1);

  EXPECT_EQ(recovery_table->GetNumberOfTuples(), 0);
  EXPECT_EQ(recovery_table->GetTileGroupCount(), 2);
}
示例#8
0
    void SetUp() override
    {
        dem = vtkSmartPointer<vtkImageData>::New();
        dem->SetExtent(extent.data());
        dem->AllocateScalars(VTK_FLOAT, 1);
        dem->GetIncrements(incs.GetData());
        auto elevations = dem->GetPointData()->GetScalars();
        elevations->SetName("Elevations");
        for (vtkIdType i = 0; i < elevations->GetNumberOfTuples(); ++i)
        {
            elevations->SetComponent(i, 0, 0.f);
        }

        dem->SetScalarComponentFromFloat(2, 3, 0, 0, 1.0);
        dem->SetScalarComponentFromFloat(2, 4, 0, 0, 1.0);
        dem->SetScalarComponentFromFloat(2, 5, 0, 0, 2.0);
    }
示例#9
0
TEST_F(TestVtkMeshConverter, Conversion)
{
    auto mesh = std::unique_ptr<MeshLib::Mesh>(
        MeshLib::VtkMeshConverter::convertUnstructuredGrid(vtu));
    ASSERT_EQ(mesh->getNNodes(), vtu->GetNumberOfPoints());
    ASSERT_EQ(mesh->getNElements(), vtu->GetNumberOfCells());
    ASSERT_EQ(mesh->getElement(0)->getCellType(), MeshLib::CellType::HEX8);

    auto meshProperties = mesh->getProperties();

    // MaterialIDs are converted to an int property
    auto materialIds = meshProperties.getPropertyVector<int>("MaterialIDs");
    ASSERT_TRUE(static_cast<bool>(materialIds));
    auto vtkMaterialIds = vtu->GetCellData()->GetArray("MaterialIDs");
    ASSERT_EQ((*materialIds).size(), vtkMaterialIds->GetNumberOfTuples());
    for(std::size_t i = 0; i < (*materialIds).size(); i++)
        ASSERT_EQ((*materialIds)[i], vtkMaterialIds->GetTuple1(i));
}
示例#10
0
    /**
     * @brief Removes Tuples from the Array. If the size of the vector is Zero nothing is done. If the size of the
     * vector is greater than or Equal to the number of Tuples then the Array is Resized to Zero. If there are
     * indices that are larger than the size of the original (before erasing operations) then an error code (-100) is
     * returned from the program.
     * @param idxs The indices to remove
     * @return error code.
     */
    virtual int EraseTuples(std::vector<size_t> &idxs)
    {
      int err = 0;
            // If nothing is to be erased just return
      if(idxs.size() == 0)
      {
        return 0;
      }

      if (idxs.size() >= GetNumberOfTuples() )
      {
        Resize(0);
        return 0;
      }

      // Sanity Check the Indices in the vector to make sure we are not trying to remove any indices that are
      // off the end of the array and return an error code.
      for(std::vector<size_t>::size_type i = 0; i < idxs.size(); ++i)
      {
        if (idxs[i] >= _data.size()) { return -100; }
      }


      std::vector<SharedVectorType> replacement(_data.size() - idxs.size());
      size_t idxsIndex = 0;
      size_t rIdx = 0;
      for(size_t dIdx = 0; dIdx < _data.size(); ++dIdx)
      {
        if (dIdx != idxs[idxsIndex])
        {
          replacement[rIdx] = _data[dIdx];
          ++rIdx;
        }
        else
        {
          ++idxsIndex;
          if (idxsIndex == idxs.size() ) { idxsIndex--;}
        }
      }
      _data = replacement;
      return err;
    }
示例#11
0
 /**
  *
  * @param parentId
  * @return
  */
 virtual int writeH5Data(hid_t parentId)
 {
   if (Array == NULL) { return -85648; }
   return H5DataArrayWriter<T>::writeArray(parentId, GetName(), GetNumberOfTuples(), GetNumberOfComponents(), Array, getFullNameOfClass());
 }
示例#12
0
    /**
     * @brief Removes Tuples from the Array. If the size of the vector is Zero nothing is done. If the size of the
     * vector is greater than or Equal to the number of Tuples then the Array is Resized to Zero. If there are
     * indices that are larger than the size of the original (before erasing operations) then an error code (-100) is
     * returned from the program.
     * @param idxs The indices to remove
     * @return error code.
     */
    virtual int EraseTuples(std::vector<size_t> &idxs)
    {

      int err = 0;

      // If nothing is to be erased just return
      if(idxs.size() == 0)
      {
        return 0;
      }

      if (idxs.size() >= GetNumberOfTuples() )
      {
        Resize(0);
        return 0;
      }

      // Sanity Check the Indices in the vector to make sure we are not trying to remove any indices that are
      // off the end of the array and return an error code.
      for(std::vector<size_t>::size_type i = 0; i < idxs.size(); ++i)
      {
        if (idxs[i] * this->NumberOfComponents > this->MaxId) { return -100; }
      }

      // Calculate the new size of the array to copy into
      size_t newSize = (GetNumberOfTuples() - idxs.size()) * NumberOfComponents ;
      T* currentSrc = this->Array;

      // Create a new Array to copy into
      T* newArray = (T*)malloc(newSize * sizeof(T));
      // Splat AB across the array so we know if we are copying the values or not
      ::memset(newArray, 0xAB, newSize * sizeof(T));

      // Keep the current Destination Pointer
      T* currentDest = newArray;
      size_t j = 0;
      size_t k = 0;
      // Find the first chunk to copy by walking the idxs array until we get an
      // index that is NOT a continuous increment from the start
      for (k = 0; k < idxs.size(); ++k)
      {
        if(j == idxs[k])
        {
          ++j;
        }
        else
        {
          break;
        }
      }

      if(k == idxs.size()) // Only front elements are being dropped
      {
        currentSrc = Array + (j * NumberOfComponents);
        ::memcpy(currentDest, currentSrc, (GetNumberOfTuples() - idxs.size()) * NumberOfComponents * sizeof(T));
        _deallocate(); // We are done copying - delete the current Array
        this->Size = newSize;
        this->Array = newArray;
        this->_ownsData = true;
        this->MaxId = newSize - 1;
        return 0;
      }

      std::vector<size_t> srcIdx(idxs.size() + 1);
      std::vector<size_t> destIdx(idxs.size() + 1);
      std::vector<size_t> copyElements(idxs.size() + 1);
      srcIdx[0] = 0;
      destIdx[0] = 0;
      copyElements[0] = (idxs[0] - 0) * NumberOfComponents;

      for (size_t i = 1; i < srcIdx.size(); ++i)
      {
        srcIdx[i] = (idxs[i - 1] + 1) * NumberOfComponents;

        if(i < srcIdx.size() - 1)
        {
          copyElements[i] = (idxs[i] - idxs[i - 1] - 1) * NumberOfComponents;
        }
        else
        {
          copyElements[i] = (GetNumberOfTuples() - idxs[i - 1] - 1) * NumberOfComponents;
        }
        destIdx[i] = copyElements[i - 1] + destIdx[i - 1];
      }

      // Copy the data
      for (size_t i = 0; i < srcIdx.size(); ++i)
      {
        currentDest = newArray + destIdx[i];
        currentSrc = Array + srcIdx[i];
        size_t bytes = copyElements[i] * sizeof(T);
        ::memcpy(currentDest, currentSrc, bytes);
      }

      // We are done copying - delete the current Array
      _deallocate();

      // Allocation was successful.  Save it.
      this->Size = newSize;
      this->Array = newArray;
      // This object has now allocated its memory and owns it.
      this->_ownsData = true;

      this->MaxId = newSize - 1;

      return err;
    }