Beispiel #1
0
func TestLeftOverwritesRight(t *testing.T) {
	expected := []optimus.Row{
		{"header1": "value3", "header2": "value2", "header3": "value1"},
	}
	leftTable := slice.New([]optimus.Row{
		{"header1": "value1", "header2": "value2"},
	})
	rightTable := slice.New([]optimus.Row{
		{"header3": "value1", "header1": "value3"},
	})

	combinedTable := optimus.Transform(leftTable, Join(rightTable, "header1", "header3", JoinType.Inner))

	rows := tests.HasRows(t, combinedTable, 1)
	assert.Equal(t, expected, rows)
}
Beispiel #2
0
func TestJoinOneToNone(t *testing.T) {
	expected := []optimus.Row{
		{"header1": "value3", "header2": "value4", "header3": "value3", "header4": "value8"},
		{"header1": "value5", "header2": "value6", "header3": "value5", "header4": "value9"},
	}

	leftTable := slice.New(defaultInput())
	rightTable := slice.New([]optimus.Row{
		// 'value1' in left table maps to no rows in the right table
		{"header3": "valueNoMatch", "header4": "value7"},
		{"header3": "value3", "header4": "value8"},
		{"header3": "value5", "header4": "value9"},
	})
	combinedTable := optimus.Transform(leftTable, Join(rightTable, "header1", "header3", JoinType.Inner))
	rows := tests.HasRows(t, combinedTable, 2)
	assert.Equal(t, expected, rows)
}
Beispiel #3
0
func TestJoinOneToMany(t *testing.T) {
	expected := []optimus.Row{
		{"header1": "value1", "header2": "value2", "header3": "value1", "header4": "value8"},
		{"header1": "value1", "header2": "value2", "header3": "value1", "header4": "value9"},
	}

	leftTable := slice.New([]optimus.Row{
		{"header1": "value1", "header2": "value2"},
	})
	rightTable := slice.New([]optimus.Row{
		// 'value1' in left table maps to two rows in the right table
		{"header3": "value1", "header4": "value8"},
		{"header3": "value1", "header4": "value9"},
	})
	combinedTable := optimus.Transform(leftTable, Join(rightTable, "header1", "header3", JoinType.Inner))
	rows := tests.HasRows(t, combinedTable, 2)
	assert.Equal(t, expected, rows)
}
// Test that chaining together multiple transforms behaves as expected
func TestChaining(t *testing.T) {
	input := []optimus.Row{
		{"header1": "value1", "header2": "value2"},
		{"header1": "value3", "header2": "value4"},
		{"header1": "value5", "header2": "value6"},
	}
	expected := []optimus.Row{
		{"header4": "value1"},
		{"header4": "value3"},
		{"header4": "value5"},
	}

	table := slice.New(input)
	transformedTable := New(table).Fieldmap(
		map[string][]string{"header1": {"header3"}}).Fieldmap(map[string][]string{"header3": {"header4"}}).Table()
	rows := tests.HasRows(t, transformedTable, 3)
	assert.Equal(t, expected, rows)
}