diff --git serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerdeUtils.java serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerdeUtils.java index 13848b6..599a4a8 100644 --- serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerdeUtils.java +++ serde/src/java/org/apache/hadoop/hive/serde2/avro/AvroSerdeUtils.java @@ -29,6 +29,8 @@ import org.apache.hadoop.mapred.JobConf; import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.List; import java.util.Properties; @@ -66,13 +68,18 @@ public static Schema determineSchemaOrThrowException(Properties properties) throw new AvroSerdeException(EXCEPTION_MESSAGE); try { - if(schemaString.toLowerCase().startsWith("hdfs://")) - return getSchemaFromHDFS(schemaString, new Configuration()); - } catch(IOException ioe) { - throw new AvroSerdeException("Unable to read schema from HDFS: " + schemaString, ioe); + Schema s = getSchemaFromFS(schemaString, new Configuration()); + if (s == null) { + LOG.warn("Serde schema not located on a known file system " + schemaString ); + //in case schema is not a file system + return Schema.parse(new URL(schemaString).openStream()); + } + return s; + } catch (IOException ioe) { + throw new AvroSerdeException("Unable to read schema from given path: " + schemaString, ioe); + } catch (URISyntaxException urie) { + throw new AvroSerdeException("Unable to read schema from given path: " + schemaString, urie); } - - return Schema.parse(new URL(schemaString).openStream()); } /** @@ -96,13 +103,18 @@ public static Schema determineSchemaOrReturnErrorSchema(Properties props) { } } // Protected for testing and so we can pass in a conf for testing. - protected static Schema getSchemaFromHDFS(String schemaHDFSUrl, - Configuration conf) throws IOException { - FileSystem fs = FileSystem.get(conf); + protected static Schema getSchemaFromFS(String schemaFSUrl, + Configuration conf) throws IOException, URISyntaxException { FSDataInputStream in = null; - + FileSystem fs = null; + try { + fs = FileSystem.get(new URI(schemaFSUrl), conf); + } catch (IOException ioe) { + //return null only if the file system in schema is not recognized + return null; + } try { - in = fs.open(new Path(schemaHDFSUrl)); + in = fs.open(new Path(schemaFSUrl)); Schema s = Schema.parse(in); return s; } finally {