5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-07 00:39:46 +08:00

SQOOP-1969: Support getColumnSize method for Schema class

(Qian Xu via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-01-05 12:13:59 +01:00
parent e8a4a97fe2
commit 1cf075fdff
4 changed files with 9 additions and 5 deletions

View File

@ -21,9 +21,9 @@
import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.common.SqoopException;
import org.apache.sqoop.schema.type.Column; import org.apache.sqoop.schema.type.Column;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -59,7 +59,7 @@ public class Schema {
private Schema() { private Schema() {
creationDate = new Date(); creationDate = new Date();
columns = new LinkedList<Column>(); columns = new ArrayList<Column>();
columNames = new HashSet<String>(); columNames = new HashSet<String>();
} }
@ -123,6 +123,10 @@ public List<Column> getColumnsList() {
return columns; return columns;
} }
public int getColumnsCount() {
return columns.size();
}
public boolean isEmpty() { public boolean isEmpty() {
return columns.size() == 0; return columns.size() == 0;
} }

View File

@ -192,7 +192,7 @@ public Object[] getObjectData() {
return null; return null;
} }
if (fieldStringArray.length != schema.getColumnsArray().length) { if (fieldStringArray.length != schema.getColumnsCount()) {
throw new SqoopException(CSVIntermediateDataFormatError.CSV_INTERMEDIATE_DATA_FORMAT_0005, throw new SqoopException(CSVIntermediateDataFormatError.CSV_INTERMEDIATE_DATA_FORMAT_0005,
"The data " + getCSVTextData() + " has the wrong number of fields."); "The data " + getCSVTextData() + " has the wrong number of fields.");
} }

View File

@ -42,7 +42,7 @@ public LocationMatcher(Schema from, Schema to) {
@Override @Override
public Object[] getMatchingData(Object[] fields) { public Object[] getMatchingData(Object[] fields) {
Object[] out = new Object[getToSchema().getColumnsArray().length]; Object[] out = new Object[getToSchema().getColumnsCount()];
int i = 0; int i = 0;

View File

@ -35,7 +35,7 @@ public NameMatcher(Schema from, Schema to) {
@Override @Override
public Object[] getMatchingData(Object[] fields) { public Object[] getMatchingData(Object[] fields) {
Object[] out = new Object[getToSchema().getColumnsArray().length]; Object[] out = new Object[getToSchema().getColumnsCount()];
HashMap<String,Column> colNames = new HashMap<String, Column>(); HashMap<String,Column> colNames = new HashMap<String, Column>();