Ejemplo n.º 1
0
template<class T> void test_const_column_insert_and_retrieve(T value)
{
    uint32_t length = 10;

    // insert
    tables::const_column column1(value);
    for (uint32_t j = 0; j < length; ++j)
    {
        column1.add_row();
    }

    // retrieve
    for (uint32_t j = 0; j < length; ++j)
    {
        EXPECT_EQ(value, boost::any_cast<T>(column1.value(j)));
    }

    // insert
    tables::const_column column2(value, length);

    // retrieve
    for (uint32_t j = 0; j < length; ++j)
    {
        EXPECT_EQ(value, boost::any_cast<T>(column2.value(j)));
    }
}
Ejemplo n.º 2
0
	//生成6个面 clip 是 wvp matrix
	/////////////////////////
	void Frustum::Construct(Matrix4x4 & clip)
	{
		Vector4  & column1(clip.GetColumn(0));
		Vector4  & column2(clip.GetColumn(1));
		Vector4  & column3(clip.GetColumn(2));
		Vector4  & column4(clip.GetColumn(3));
		//根据平面方程
		//Near:    (P0,P4,P5)     n=(0,0,-1),d=0              0x+0y-1z+0=0     
		m_planes[0] = column4 - column3;//这个函数规格化平面方程,使|a,b,c| == 1。
		//Far:      (P2,P6,P7)     n=(0,0,1),d=-1              0x+0y+1z-1=0  
		m_planes[1] = column4 + column3;
		//Left:     (P0,P3,P7)     n=(-1,0,0),d=-1          -1x+0y+0z-1=0     
		m_planes[2] = column4 - column1;
		//Right:    (P1,P5,P6)     n=(1,0,0),d=-1              1x+0y+0z-1=0    
		m_planes[3] = column4 + column1;
		//Top:      (P4,P7,P6)     n=(0,1,0),d=-1              0x+1y+0z-1=0   
		m_planes[4] = column4 + column2;
		//Bottom:   (P0,P1,P2)     n=(0,-1,0),d=-1            0x-1y+0z-1=0     
		m_planes[5] = column4 - column2;
		//归一
		for(int i=0; i<6; i++)
		{
			m_planes[i].Normalize();
		}
		//做个标记???
		//  build a bit-field that will tell us the indices for the nearest and farthest vertices from each plane...
		for(int i=0; i<6; i++)
		{
			m_flag[i]  = ((m_planes[i].x<0) ? 1 : 0) | ((m_planes[i].y<0) ? 2 : 0) | ((m_planes[i].z) ? 4 : 0);
		}

	}
Ejemplo n.º 3
0
TEST_F(TupleSchemaTests, TupleSchemaTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_VARCHAR, 24, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema schema1(columns);
  LOG_INFO("%s", schema1.GetInfo().c_str());

  catalog::Schema schema2(columns);
  EXPECT_EQ(schema1, schema2);

  std::vector<oid_t> subset{0, 2};
  catalog::Schema *schema3 = catalog::Schema::CopySchema(&schema2, subset);
  LOG_INFO("%s", schema3->GetInfo().c_str());

  EXPECT_NE(schema1, (*schema3));

  delete schema3;
}
Ejemplo n.º 4
0
TEST_F(ExpressionTests, SimpleCaseCopyTest) {

  // CASE WHEN i=1 THEN 2 ELSE 3 END
  // EXPRESSION
  auto tup_val_exp = new expression::TupleValueExpression(type::TypeId::INTEGER,
      0, 0);
  auto const_val_exp_1 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(1));
  auto const_val_exp_2 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(2));
  auto const_val_exp_3 = new expression::ConstantValueExpression(
      type::ValueFactory::GetIntegerValue(3));

  auto *when_cond =
      new expression::ComparisonExpression(ExpressionType::COMPARE_EQUAL,
          tup_val_exp, const_val_exp_1);

  std::vector<expression::CaseExpression::WhenClause> clauses;
  clauses.push_back(expression::CaseExpression::WhenClause(
      expression::CaseExpression::AbsExprPtr(when_cond),
      expression::CaseExpression::AbsExprPtr(const_val_exp_2)));

  std::unique_ptr<expression::CaseExpression> o_case_expression(
      new expression::CaseExpression(type::TypeId::INTEGER, clauses,
          expression::CaseExpression::AbsExprPtr(const_val_exp_3)));

  std::unique_ptr<expression::CaseExpression> case_expression(
      dynamic_cast<expression::CaseExpression *>(o_case_expression->Copy()));

  // TUPLE
  std::vector<catalog::Column> columns;

  catalog::Column column1(type::TypeId::INTEGER,
                          type::Type::GetTypeSize(type::TypeId::INTEGER),
                          "i1", true);
  catalog::Column column2(type::TypeId::INTEGER,
                          type::Type::GetTypeSize(type::TypeId::INTEGER),
                          "i2", true);
  columns.push_back(column1);
  columns.push_back(column2);
  std::unique_ptr<catalog::Schema> schema(new catalog::Schema(columns));

  std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema.get(), true));

  // Test with A = 1, should get 2
  tuple->SetValue(0, type::ValueFactory::GetIntegerValue(1), nullptr);
  tuple->SetValue(1, type::ValueFactory::GetIntegerValue(1), nullptr);
  type::Value result = case_expression->Evaluate(tuple.get(), nullptr, nullptr);
  type::Value expected = type::ValueFactory::GetIntegerValue(2);
  EXPECT_EQ(type::CmpBool::CMP_TRUE, expected.CompareEquals(result));

  // Test with A = 2, should get 3
  tuple->SetValue(0, type::ValueFactory::GetIntegerValue(2), nullptr);
  tuple->SetValue(1, type::ValueFactory::GetIntegerValue(1), nullptr);
  result = case_expression->Evaluate(tuple.get(), nullptr, nullptr);
  expected = type::ValueFactory::GetIntegerValue(3);
  EXPECT_EQ(type::CmpBool::CMP_TRUE, expected.CompareEquals(result));
}
Ejemplo n.º 5
0
TEST_F(ExpressionTests, DistinctFromTest) {
  // Create a table with id column and value column
  std::vector<catalog::Column> columns;

  catalog::Column column1(type::TypeId::INTEGER,
                          type::Type::GetTypeSize(type::TypeId::INTEGER), "id",
                          true);
  catalog::Column column2(type::TypeId::INTEGER,
                          type::Type::GetTypeSize(type::TypeId::INTEGER), "value",
                          true);

  columns.push_back(column1);
  columns.push_back(column2);

  std::unique_ptr<catalog::Schema> schema(new catalog::Schema(columns));

  std::unique_ptr<storage::Tuple> tuple(new storage::Tuple(schema.get(), true));

  // Create "id IS DISTINCT FROM value" comparison
  auto lexpr = new expression::TupleValueExpression(type::TypeId::INTEGER, 0, 0);
  auto rexpr = new expression::TupleValueExpression(type::TypeId::INTEGER, 1, 1);

  expression::ComparisonExpression expr(
      StringToExpressionType("COMPARE_DISTINCT_FROM"), lexpr, rexpr);

  auto pool = TestingHarness::GetInstance().GetTestingPool();

  // id, value not NULL with the same values, should be false
  tuple->SetValue(0, type::ValueFactory::GetIntegerValue(10), pool);
  tuple->SetValue(1, type::ValueFactory::GetIntegerValue(10), pool);
  EXPECT_TRUE(expr.Evaluate(tuple.get(), tuple.get(), nullptr).IsFalse());

  // id, value not NULL with different values, should be true
  tuple->SetValue(1, type::ValueFactory::GetIntegerValue(5), pool);
  EXPECT_TRUE(expr.Evaluate(tuple.get(), tuple.get(), nullptr).IsTrue());

  // id not NULL, value is NULL, should be true
  tuple->SetValue(1,
      type::ValueFactory::GetNullValueByType(type::TypeId::INTEGER), pool);
  EXPECT_TRUE(expr.Evaluate(tuple.get(), tuple.get(), nullptr).IsTrue());

  // id is NULL, value not NULL, should be true
  tuple->SetValue(0,
      type::ValueFactory::GetNullValueByType(type::TypeId::INTEGER), pool);
  tuple->SetValue(1, type::ValueFactory::GetIntegerValue(10), pool);
  EXPECT_TRUE(expr.Evaluate(tuple.get(), tuple.get(), nullptr).IsTrue());

  // id is NULL, value is NULL, should be false
  tuple->SetValue(1,
       type::ValueFactory::GetNullValueByType(type::TypeId::INTEGER), pool);
  EXPECT_TRUE(expr.Evaluate(tuple.get(), tuple.get(), nullptr).IsFalse());
}
Ejemplo n.º 6
0
TEST_F(TupleTests, VarcharTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "A", true);
  catalog::Column column2(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "B", true);
  catalog::Column column3(common::Type::TINYINT, common::Type::GetTypeSize(common::Type::TINYINT),
                          "C", true);
  catalog::Column column4(common::Type::VARCHAR, 25, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, common::ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, common::ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(1), pool);

  common::Value val = common::ValueFactory::GetVarcharValue("hello hello world", pool);
  tuple->SetValue(3, val, pool);
  common::Value value3 = (tuple->GetValue(3));
  common::Value cmp = (value3.CompareEquals(val));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  auto val2 = common::ValueFactory::GetVarcharValue("hi joy !", pool);
  tuple->SetValue(3, val2, pool);
  value3 = (tuple->GetValue(3));
  cmp = (value3.CompareNotEquals(val));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (value3.CompareEquals(val2));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
Ejemplo n.º 7
0
TEST_F(TupleTests, BasicTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "A", true);
  catalog::Column column2(common::Type::INTEGER, common::Type::GetTypeSize(common::Type::INTEGER),
                          "B", true);
  catalog::Column column3(common::Type::TINYINT, common::Type::GetTypeSize(common::Type::TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, common::ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, common::ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(1), pool);

  common::Value val0 = (tuple->GetValue(0));
  common::Value val1 = (tuple->GetValue(1));
  common::Value val2 = (tuple->GetValue(2));

  common::Value cmp = (val0.CompareEquals(
      common::ValueFactory::GetIntegerValue(23)));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (val1.CompareEquals(common::ValueFactory::GetIntegerValue(45)));
  EXPECT_TRUE(cmp.IsTrue());
  cmp = (val2.CompareEquals(common::ValueFactory::GetIntegerValue(1)));
  EXPECT_TRUE(cmp.IsTrue());

  tuple->SetValue(2, common::ValueFactory::GetTinyIntValue(2), pool);

  val2 = (tuple->GetValue(2));
  cmp = (val2.CompareEquals(common::ValueFactory::GetIntegerValue(2)));
  EXPECT_TRUE(cmp.IsTrue());

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
Ejemplo n.º 8
0
TEST_F(TupleSchemaTests, ColumnInfoTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  EXPECT_EQ(column1, column2);
  EXPECT_NE(column1, column3);
}
index::Index *BuildIndex(const bool unique_keys, const IndexType index_type) {
  // Build tuple and key schema
  std::vector<std::vector<std::string>> column_names;
  std::vector<catalog::Column> columns;
  std::vector<catalog::Schema *> schemas;

  catalog::Column column1(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "A",
                          true);
  catalog::Column column2(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "B",
                          true);
  catalog::Column column3(type::Type::DECIMAL,
                          type::Type::GetTypeSize(type::Type::DECIMAL), "C",
                          true);
  catalog::Column column4(type::Type::INTEGER,
                          type::Type::GetTypeSize(type::Type::INTEGER), "D",
                          true);

  columns.push_back(column1);
  columns.push_back(column2);

  // INDEX KEY SCHEMA -- {column1, column2}
  std::vector<oid_t> key_attrs = {0, 1};
  key_schema = new catalog::Schema(columns);
  key_schema->SetIndexedColumns(key_attrs);

  columns.push_back(column3);
  columns.push_back(column4);

  // TABLE SCHEMA -- {column1, column2, column3, column4}
  tuple_schema = new catalog::Schema(columns);

  // Build index metadata
  index::IndexMetadata *index_metadata = new index::IndexMetadata(
      "test_index", 125, INVALID_OID, INVALID_OID, index_type,
      IndexConstraintType::DEFAULT, tuple_schema, key_schema, key_attrs,
      unique_keys);

  // Build index
  index::Index *index = index::IndexFactory::GetIndex(index_metadata);
  EXPECT_TRUE(index != NULL);

  return index;
}
Ejemplo n.º 10
0
index::Index *BuildIndex() {
  // Build tuple and key schema
  std::vector<std::vector<std::string>> column_names;
  std::vector<catalog::Column> columns;
  std::vector<catalog::Schema *> schemas;
  IndexType index_type = INDEX_TYPE_BTREE;
  // TODO: Uncomment the line below
  index_type = INDEX_TYPE_BWTREE;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_VARCHAR, 1024, "B", true);
  catalog::Column column3(VALUE_TYPE_DOUBLE, GetTypeSize(VALUE_TYPE_DOUBLE),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "D", true);

  columns.push_back(column1);
  columns.push_back(column2);

  // INDEX KEY SCHEMA -- {column1, column2}
  key_schema = new catalog::Schema(columns);
  key_schema->SetIndexedColumns({0, 1});

  columns.push_back(column3);
  columns.push_back(column4);

  // TABLE SCHEMA -- {column1, column2, column3, column4}
  tuple_schema = new catalog::Schema(columns);

  // Build index metadata
  const bool unique_keys = false;

  index::IndexMetadata *index_metadata = new index::IndexMetadata(
      "test_index", 125, index_type, INDEX_CONSTRAINT_TYPE_DEFAULT,
      tuple_schema, key_schema, unique_keys);

  // Build index
  index::Index *index = index::IndexFactory::GetInstance(index_metadata);
  EXPECT_TRUE(index != NULL);

  return index;
}
Ejemplo n.º 11
0
TEST_F(TupleTests, VarcharTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);
  catalog::Column column4(VALUE_TYPE_VARCHAR, 25, "D", false);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);
  columns.push_back(column4);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, ValueFactory::GetTinyIntValue(1), pool);

  Value val = ValueFactory::GetStringValue("hello hello world", pool);
  tuple->SetValue(3, val, pool);
  EXPECT_EQ(tuple->GetValue(3), val);

  LOG_INFO("%s", tuple->GetInfo().c_str());

  Value val2 = ValueFactory::GetStringValue("hi joy !", pool);
  tuple->SetValue(3, val2, pool);

  EXPECT_NE(tuple->GetValue(3), val);
  EXPECT_EQ(tuple->GetValue(3), val2);

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}
Ejemplo n.º 12
0
Frustum::Frustum( const SMatrix4x4& matrix )
{
	//  build a view frustum based on the current view & projection matrices...
	SVector4 column4( matrix._14, matrix._24, matrix._34, matrix._44 );
	SVector4 column1( matrix._11, matrix._21, matrix._31, matrix._41 );
	SVector4 column2( matrix._12, matrix._22, matrix._32, matrix._42 );
	SVector4 column3( matrix._13, matrix._23, matrix._33, matrix._43 );

	SVector4 planes[6];
	planes[0] = column4 - column1;  // left
	planes[1] = column4 + column1;  // right
	planes[2] = column4 - column2;  // bottom
	planes[3] = column4 + column2;  // top
	planes[4] = column4 - column3;  // near
	planes[5] = column4 + column3;  // far

	int p;

	for (p=0; p<6; p++)  // normalize the planes
	{
		float dot = planes[p].x*planes[p].x + planes[p].y*planes[p].y + planes[p].z*planes[p].z;
		dot = 1.0f / sqrtf(dot);
		planes[p] = planes[p] * dot;
	}

	for (p=0; p<6; p++)
		camPlanes[p] = SPlane( planes[p].x, planes[p].y, planes[p].z, planes[p].w );

	//  build a bit-field that will tell us the indices for the nearest and farthest vertices from each plane...
	for (int i=0; i<6; i++)
		nVertexLUT[i] = ((planes[i].x<0.f)?1:0) | ((planes[i].y<0.f)?2:0) | ((planes[i].z<0.f)?4:0);

	for( int i=0; i<8; ++i ) // compute extrema
	{
		const SPlane& p0 = (i&1)?camPlanes[4] : camPlanes[5];
		const SPlane& p1 = (i&2)?camPlanes[3] : camPlanes[2];
		const SPlane& p2 = (i&4)?camPlanes[0] : camPlanes[1];

		PlaneIntersection( &pntList[i], p0, p1, p2 );
	}
}
Ejemplo n.º 13
0
TEST_F(TupleTests, BasicTest) {
  std::vector<catalog::Column> columns;

  catalog::Column column1(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "A", true);
  catalog::Column column2(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                          "B", true);
  catalog::Column column3(VALUE_TYPE_TINYINT, GetTypeSize(VALUE_TYPE_TINYINT),
                          "C", true);

  columns.push_back(column1);
  columns.push_back(column2);
  columns.push_back(column3);

  catalog::Schema *schema(new catalog::Schema(columns));

  storage::Tuple *tuple(new storage::Tuple(schema, true));
  auto pool = TestingHarness::GetInstance().GetTestingPool();

  tuple->SetValue(0, ValueFactory::GetIntegerValue(23), pool);
  tuple->SetValue(1, ValueFactory::GetIntegerValue(45), pool);
  tuple->SetValue(2, ValueFactory::GetTinyIntValue(1), pool);

  EXPECT_EQ(tuple->GetValue(0), ValueFactory::GetIntegerValue(23));
  EXPECT_EQ(tuple->GetValue(1), ValueFactory::GetIntegerValue(45));
  EXPECT_EQ(tuple->GetValue(2), ValueFactory::GetTinyIntValue(1));

  tuple->SetValue(2, ValueFactory::GetTinyIntValue(2), pool);

  EXPECT_EQ(tuple->GetValue(2), ValueFactory::GetTinyIntValue(2));

  LOG_INFO("%s", tuple->GetInfo().c_str());

  delete tuple;
  delete schema;
}