mirror of
https://github.com/apache/sqoop.git
synced 2025-05-20 02:40:52 +08:00
SQOOP-1761: Sqoop2: Unit tests for different Column sub classes Array/Set and Map types
(Veena Basavaraj via Abraham Elmahrek)
This commit is contained in:
parent
6bd8fe3e93
commit
deacc90c49
@ -260,7 +260,7 @@ private static Column restoreColumn(JSONObject obj) {
|
||||
output = new Map(name, key, value);
|
||||
break;
|
||||
case SET:
|
||||
output = new Set(name).setListType(listType);
|
||||
output = new Set(name, listType);
|
||||
break;
|
||||
case TEXT:
|
||||
charSize = (Long) obj.get(CHAR_SIZE);
|
||||
|
@ -23,6 +23,7 @@
|
||||
public abstract class AbstractComplexListType extends AbstractComplexType {
|
||||
|
||||
// represents the type of the list elements
|
||||
// NOTE: required for Array/Set, optional for Enum
|
||||
Column listType;
|
||||
|
||||
public AbstractComplexListType(String name) {
|
||||
@ -54,28 +55,29 @@ public String toString() {
|
||||
return new StringBuilder(super.toString()).append(",listType=").append(listType).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof AbstractComplexListType))
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
AbstractComplexListType that = (AbstractComplexListType) o;
|
||||
|
||||
if (listType != null ? !listType.equals(that.listType) : that.listType != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (listType != null ? listType.hashCode() : 0);
|
||||
result = prime * result + ((listType == null) ? 0 : listType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
AbstractComplexListType other = (AbstractComplexListType) obj;
|
||||
if (listType == null) {
|
||||
if (other.listType != null)
|
||||
return false;
|
||||
} else if (!listType.equals(other.listType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ public ColumnType getType() {
|
||||
public String toString() {
|
||||
return new StringBuilder("Array{").
|
||||
append(super.toString()).
|
||||
append(", size=").
|
||||
append(size).
|
||||
append("}").toString();
|
||||
}
|
||||
|
||||
|
@ -66,30 +66,34 @@ public String toString() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof Map))
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
Map map = (Map) o;
|
||||
|
||||
if (key != null ? !key.equals(map.key) : map.key != null)
|
||||
return false;
|
||||
|
||||
if (value != null ? !value.equals(map.value) : map.value != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((key == null) ? 0 : key.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (key != null ? key.hashCode() : 0);
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
return result;
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Map other = (Map) obj;
|
||||
if (key == null) {
|
||||
if (other.key != null)
|
||||
return false;
|
||||
} else if (!key.equals(other.key))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,10 +24,6 @@
|
||||
*/
|
||||
public class Set extends AbstractComplexListType {
|
||||
|
||||
public Set(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public Set(String name, Column listType) {
|
||||
super(name, listType);
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.sqoop.schema.type;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestArray {
|
||||
|
||||
@Test
|
||||
public void testArrayWithSameListType() {
|
||||
Array a1 = new Array("A", new Text("T"));
|
||||
Array a2 = new Array("A", new Text("T"));
|
||||
assertTrue(a1.equals(a2));
|
||||
assertEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayWithDifferentName() {
|
||||
Array a1 = new Array("A", new Text("T"));
|
||||
Array a2 = new Array("B", new Text("T"));
|
||||
assertFalse(a1.equals(a2));
|
||||
assertNotEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayWithDifferentSize() {
|
||||
Array a1 = new Array("A", new Text("T")).setSize(22L);
|
||||
Array a2 = new Array("A", new Text("T")).setSize(2333L);
|
||||
assertFalse(a1.equals(a2));
|
||||
assertNotEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayWithDifferentListType() {
|
||||
Array a1 = new Array("A", new Text("T"));
|
||||
Array a2 = new Array("A", new Binary("B"));
|
||||
assertFalse(a1.equals(a2));
|
||||
assertNotEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.sqoop.schema.type;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestEnum {
|
||||
|
||||
@Test
|
||||
public void testEnumWithNoOptions() {
|
||||
Enum e1 = new Enum("A");
|
||||
Enum e2 = new Enum("A");
|
||||
assertTrue(e1.equals(e2));
|
||||
assertEquals(e1.toString(), e2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumWithDifferentOptions() {
|
||||
Enum e1 = new Enum("A").setOptions(Collections.unmodifiableSet(new HashSet<String>(Arrays
|
||||
.asList(new String[] { "A", "B" }))));
|
||||
Enum e2 = new Enum("A").setOptions(Collections.unmodifiableSet(new HashSet<String>(Arrays
|
||||
.asList(new String[] { "A1", "B1" }))));
|
||||
assertFalse(e1.equals(e2));
|
||||
assertNotEquals(e1.toString(), e2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumWithSameOptions() {
|
||||
Enum e1 = new Enum("A").setOptions(Collections.unmodifiableSet(new HashSet<String>(Arrays
|
||||
.asList(new String[] { "A", "B" }))));
|
||||
Enum e2 = new Enum("A").setOptions(Collections.unmodifiableSet(new HashSet<String>(Arrays
|
||||
.asList(new String[] { "A", "B" }))));
|
||||
assertTrue(e1.equals(e2));
|
||||
assertEquals(e1.toString(), e2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumWithDifferentListType() {
|
||||
Enum e1 = new Enum("A");
|
||||
e1.setListType(new Text("T"));
|
||||
Enum e2 = new Enum("A");
|
||||
e2.setListType(new Binary("B"));
|
||||
assertFalse(e1.equals(e2));
|
||||
assertNotEquals(e1.toString(), e2.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.sqoop.schema.type;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestMap {
|
||||
|
||||
@Test
|
||||
public void testMapWithSameListKeyValue() {
|
||||
Map m1 = new Map("m1", new Text("T"), new Text("T"));
|
||||
Map m2 = new Map("m1", new Text("T"), new Text("T"));
|
||||
assertTrue(m1.equals(m2));
|
||||
assertEquals(m1.toString(), m2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithDifferentName() {
|
||||
Map m1 = new Map("m1", new Text("T"), new Text("T"));
|
||||
Map m2 = new Map("m2", new Text("T"), new Text("T"));
|
||||
assertFalse(m1.equals(m2));
|
||||
assertNotEquals(m1.toString(), m2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithDifferentKey() {
|
||||
Map m1 = new Map("m1", new Text("T"), new Text("T"));
|
||||
Map m2 = new Map("m1", new Text("T2"), new Text("T"));
|
||||
assertFalse(m1.equals(m2));
|
||||
assertNotEquals(m1.toString(), m2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapWithDifferentValue() {
|
||||
Map m1 = new Map("m1", new Text("T"), new Text("T2"));
|
||||
Map m2 = new Map("m1", new Text("T2"), new Text("T4"));
|
||||
assertFalse(m1.equals(m2));
|
||||
assertNotEquals(m1.toString(), m2.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.sqoop.schema.type;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestSet {
|
||||
|
||||
@Test
|
||||
public void testSetWithSameListType() {
|
||||
Set a1 = new Set("A", new Text("T"));
|
||||
Set a2 = new Set("A", new Text("T"));
|
||||
assertTrue(a1.equals(a2));
|
||||
assertEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetWithDifferentName() {
|
||||
Set a1 = new Set("A", new Text("T"));
|
||||
Set a2 = new Set("B", new Text("T"));
|
||||
assertFalse(a1.equals(a2));
|
||||
assertNotEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetWithDifferentListType() {
|
||||
Set a1 = new Set("A", new Text("T"));
|
||||
Set a2 = new Set("A", new Binary("B"));
|
||||
assertFalse(a1.equals(a2));
|
||||
assertNotEquals(a1.toString(), a2.toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user