mirror of
https://github.com/apache/sqoop.git
synced 2025-05-05 04:20:08 +08:00
SQOOP-1879: Sqoop2: Convert the List in Schema Columns to Array for better lookup time
(Veena Basavaraj via Abraham Elmahrek)
This commit is contained in:
parent
a97d10cd78
commit
43160f72d4
@ -90,7 +90,7 @@ public static JSONObject extractSchema(Schema schema) {
|
|||||||
object.put(NOTE, schema.getNote());
|
object.put(NOTE, schema.getNote());
|
||||||
}
|
}
|
||||||
JSONArray columnArray = new JSONArray();
|
JSONArray columnArray = new JSONArray();
|
||||||
for (Column column : schema.getColumns()) {
|
for (Column column : schema.getColumnsArray()) {
|
||||||
columnArray.add(extractColumn(column));
|
columnArray.add(extractColumn(column));
|
||||||
}
|
}
|
||||||
object.put(COLUMNS, columnArray);
|
object.put(COLUMNS, columnArray);
|
||||||
|
@ -117,7 +117,11 @@ public Schema setCreationDate(Date creationDate) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Column> getColumns() {
|
public Column[] getColumnsArray() {
|
||||||
|
return columns.toArray(new Column[columns.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Column> getColumnsList() {
|
||||||
return columns;
|
return columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public void extract(ExtractorContext context, LinkConfiguration linkConfig,
|
|||||||
ResultSet resultSet = executor.executeQuery(query);
|
ResultSet resultSet = executor.executeQuery(query);
|
||||||
|
|
||||||
Schema schema = context.getSchema();
|
Schema schema = context.getSchema();
|
||||||
Column[] schemaColumns = schema.getColumns().toArray(new Column[schema.getColumns().size()]);
|
Column[] schemaColumns = schema.getColumnsArray();
|
||||||
try {
|
try {
|
||||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||||
int columnCount = metaData.getColumnCount();
|
int columnCount = metaData.getColumnCount();
|
||||||
|
@ -59,7 +59,7 @@ public static Schema createAvroSchema(
|
|||||||
Schema schema = Schema.createRecord(name, doc, namespace, false);
|
Schema schema = Schema.createRecord(name, doc, namespace, false);
|
||||||
|
|
||||||
List<Schema.Field> fields = new ArrayList<Schema.Field>();
|
List<Schema.Field> fields = new ArrayList<Schema.Field>();
|
||||||
for (Column column : sqoopSchema.getColumns()) {
|
for (Column column : sqoopSchema.getColumnsArray()) {
|
||||||
Schema.Field field = new Schema.Field(column.getName(),
|
Schema.Field field = new Schema.Field(column.getName(),
|
||||||
createAvroFieldSchema(column), null, null);
|
createAvroFieldSchema(column), null, null);
|
||||||
field.addProp(SQOOP_TYPE, column.getType().toString());
|
field.addProp(SQOOP_TYPE, column.getType().toString());
|
||||||
|
@ -100,7 +100,7 @@ public void setSchema(Schema schema) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
List<Column> columns = schema.getColumns();
|
Column[] columns = schema.getColumnsArray();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Column col : columns) {
|
for (Column col : columns) {
|
||||||
if (isColumnStringType(col)) {
|
if (isColumnStringType(col)) {
|
||||||
@ -192,13 +192,13 @@ public Object[] getObjectData() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldStringArray.length != schema.getColumns().size()) {
|
if (fieldStringArray.length != schema.getColumnsArray().length) {
|
||||||
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object[] objectArray = new Object[fieldStringArray.length];
|
Object[] objectArray = new Object[fieldStringArray.length];
|
||||||
Column[] columnArray = schema.getColumns().toArray(new Column[fieldStringArray.length]);
|
Column[] columnArray = schema.getColumnsArray();
|
||||||
for (int i = 0; i < fieldStringArray.length; i++) {
|
for (int i = 0; i < fieldStringArray.length; i++) {
|
||||||
// check for NULL field and bail out immediately
|
// check for NULL field and bail out immediately
|
||||||
if (fieldStringArray[i].equals(NULL_VALUE)) {
|
if (fieldStringArray[i].equals(NULL_VALUE)) {
|
||||||
@ -266,7 +266,7 @@ private Object toObject(String csvString, Column column) {
|
|||||||
@Override
|
@Override
|
||||||
public void setObjectData(Object[] data) {
|
public void setObjectData(Object[] data) {
|
||||||
Set<Integer> nullValueIndices = new HashSet<Integer>();
|
Set<Integer> nullValueIndices = new HashSet<Integer>();
|
||||||
Column[] columnArray = schema.getColumns().toArray(new Column[data.length]);
|
Column[] columnArray = schema.getColumnsArray();
|
||||||
// check for null
|
// check for null
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
if (data[i] == null) {
|
if (data[i] == null) {
|
||||||
|
@ -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().getColumns().size()];
|
Object[] out = new Object[getToSchema().getColumnsArray().length];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public Object[] getMatchingData(Object[] fields) {
|
|||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Column col: getToSchema().getColumns()) {
|
for (Column col: getToSchema().getColumnsArray()) {
|
||||||
if (i < fields.length) {
|
if (i < fields.length) {
|
||||||
if (isNull(fields[i])) {
|
if (isNull(fields[i])) {
|
||||||
out[i] = null;
|
out[i] = null;
|
||||||
|
@ -35,21 +35,21 @@ public NameMatcher(Schema from, Schema to) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getMatchingData(Object[] fields) {
|
public Object[] getMatchingData(Object[] fields) {
|
||||||
Object[] out = new Object[getToSchema().getColumns().size()];
|
Object[] out = new Object[getToSchema().getColumnsArray().length];
|
||||||
|
|
||||||
HashMap<String,Column> colNames = new HashMap<String, Column>();
|
HashMap<String,Column> colNames = new HashMap<String, Column>();
|
||||||
|
|
||||||
for (Column fromCol: getFromSchema().getColumns()) {
|
for (Column fromCol: getFromSchema().getColumnsArray()) {
|
||||||
colNames.put(fromCol.getName(), fromCol);
|
colNames.put(fromCol.getName(), fromCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
int toIndex = 0;
|
int toIndex = 0;
|
||||||
|
|
||||||
for (Column toCol: getToSchema().getColumns()) {
|
for (Column toCol: getToSchema().getColumnsArray()) {
|
||||||
Column fromCol = colNames.get(toCol.getName());
|
Column fromCol = colNames.get(toCol.getName());
|
||||||
|
|
||||||
if (fromCol != null) {
|
if (fromCol != null) {
|
||||||
int fromIndex = getFromSchema().getColumns().indexOf(fromCol);
|
int fromIndex = getFromSchema().getColumnsList().indexOf(fromCol);
|
||||||
if (isNull(fields[fromIndex])) {
|
if (isNull(fields[fromIndex])) {
|
||||||
out[toIndex] = null;
|
out[toIndex] = null;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user