use of org.apache.hive.storage.jdbc.dao.DatabaseAccessor in project hive by apache.
the class JdbcSerDe method initialize.
/*
* This method gets called multiple times by Hive. On some invocations, the properties will be empty.
* We need to detect when the properties are not empty to initialise the class variables.
*
* @see org.apache.hadoop.hive.serde2.Deserializer#initialize(org.apache.hadoop.conf.Configuration, java.util.Properties)
*/
@Override
public void initialize(Configuration conf, Properties tbl) throws SerDeException {
try {
LOGGER.debug("Initializing the SerDe");
// Hive cdh-4.3 does not provide the properties object on all calls
if (tbl.containsKey(JdbcStorageConfig.DATABASE_TYPE.getPropertyName())) {
Configuration tableConfig = JdbcStorageConfigManager.convertPropertiesToConfiguration(tbl);
DatabaseAccessor dbAccessor = DatabaseAccessorFactory.getAccessor(tableConfig);
columnNames = dbAccessor.getColumnNames(tableConfig);
numColumns = columnNames.size();
String[] hiveColumnNameArray = parseProperty(tbl.getProperty(serdeConstants.LIST_COLUMNS), ",");
if (numColumns != hiveColumnNameArray.length) {
throw new SerDeException("Expected " + numColumns + " columns. Table definition has " + hiveColumnNameArray.length + " columns");
}
List<String> hiveColumnNames = Arrays.asList(hiveColumnNameArray);
hiveColumnTypeArray = parseProperty(tbl.getProperty(serdeConstants.LIST_COLUMN_TYPES), ":");
if (hiveColumnTypeArray.length == 0) {
throw new SerDeException("Received an empty Hive column type definition");
}
List<ObjectInspector> fieldInspectors = new ArrayList<ObjectInspector>(numColumns);
for (int i = 0; i < numColumns; i++) {
fieldInspectors.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector);
}
objectInspector = ObjectInspectorFactory.getStandardStructObjectInspector(hiveColumnNames, fieldInspectors);
row = new ArrayList<String>(numColumns);
}
} catch (Exception e) {
LOGGER.error("Caught exception while initializing the SqlSerDe", e);
throw new SerDeException(e);
}
}
Aggregations