use of org.apache.carbondata.processing.loading.complexobjects.ArrayObject in project carbondata by apache.
the class MapParserImpl method parse.
// The Key for Map will always be a PRIMITIVE type so Set<Object> here will work fine
// The last occurance of the key, value pair will be added and all others will be overwritten
@Override
public Object parse(Object data) {
if (data != null) {
String value = data.toString();
if (!value.isEmpty() && !value.equals(nullFormat) && // && !value.equals(keyValueDelimiter)
!value.equals(CarbonCommonConstants.SIZE_ZERO_DATA_RETURN)) {
String[] split = pattern.split(value, -1);
if (ArrayUtils.isNotEmpty(split)) {
ArrayList<Object> array = new ArrayList<>();
Map<Object, String> map = new HashMap<>();
for (int i = 0; i < split.length; i++) {
Object[] splitedKeyAndValue = split[i].split(keyValueDelimiter);
// When both key and value are EMPTY_STRING, the length of the splitted
// result will be 0. Then the currKey should be initialized as a empty object.
// Otherwise, the arrayindexoutexception will be throwed.
Object currKey = splitedKeyAndValue.length > 0 ? split[i].split(keyValueDelimiter)[0] : new Object();
map.put(currKey, split[i]);
}
for (Map.Entry<Object, String> entry : map.entrySet()) {
array.add(child.parse(entry.getValue()));
}
return new ArrayObject(array.toArray());
}
} else if (value.isEmpty()) {
Object[] array = new Object[1];
array[0] = value;
return new ArrayObject(array);
} else if (value.equals(CarbonCommonConstants.SIZE_ZERO_DATA_RETURN)) {
// When the data is not map('','') but map(), an array with zero size should be returned.
Object[] array = new Object[0];
return new ArrayObject(array);
}
}
return null;
}
use of org.apache.carbondata.processing.loading.complexobjects.ArrayObject in project carbondata by apache.
the class JsonRowParser method jsonChildElementToCarbonChildElement.
private Object jsonChildElementToCarbonChildElement(Object childObject, CarbonDimension column) {
if (childObject == null) {
return null;
}
DataType type = column.getDataType();
if (DataTypes.isArrayType(type)) {
ArrayList array = (ArrayList) childObject;
if (array.size() == 0) {
// handling empty array
return null;
}
// stored as array in carbonObject
Object[] arrayChildObjects = new Object[array.size()];
for (int i = 0; i < array.size(); i++) {
// array column will have only one child, hence get(0).
// But data can have n elements, hence the loop.
CarbonDimension childCol = column.getListOfChildDimensions().get(0);
arrayChildObjects[i] = jsonChildElementToCarbonChildElement(array.get(i), childCol);
}
return new ArrayObject(arrayChildObjects);
} else if (DataTypes.isStructType(type)) {
Map<String, Object> childFieldsMap = (Map<String, Object>) childObject;
int size = column.getNumberOfChild();
Object[] structChildObjects = new Object[size];
for (int i = 0; i < size; i++) {
CarbonDimension childCol = column.getListOfChildDimensions().get(i);
Object child = jsonChildElementToCarbonChildElement(childFieldsMap.get(extractChildColumnName(childCol)), childCol);
structChildObjects[i] = child;
}
return new StructObject(structChildObjects);
} else {
// primitive type
return childObject.toString();
}
}
Aggregations