AvroUtil { public static Schema getAvroSchema(TableMeta meta, Configuration conf) throws IOException { boolean isSchemaLiteral = meta.containsOption(StorageConstants.AVRO_SCHEMA_LITERAL); boolean isSchemaUrl = meta.containsOption(StorageConstants.AVRO_SCHEMA_URL); if (!isSchemaLiteral && !isSchemaUrl) { throw new RuntimeException("No Avro schema for table."); } if (isSchemaLiteral) { String schema = meta.getOption(StorageConstants.AVRO_SCHEMA_LITERAL); return new Schema.Parser().parse(schema); } String schemaURL = meta.getOption(StorageConstants.AVRO_SCHEMA_URL); if (schemaURL.toLowerCase().startsWith("http")) { return getAvroSchemaFromHttp(schemaURL); } else { return getAvroSchemaFromFileSystem(schemaURL, conf); } }  static Schema getAvroSchema(TableMeta meta, Configuration conf); static Schema getAvroSchemaFromHttp(String schemaURL); static Schema getAvroSchemaFromFileSystem(String schemaURL, Configuration conf);  }
@Test public void testGetSchema() throws IOException, URISyntaxException { TableMeta meta = CatalogUtil.newTableMeta("AVRO"); meta.putOption(StorageConstants.AVRO_SCHEMA_LITERAL, FileUtil.readTextFile(new File(schemaUrl.getPath()))); Schema schema = AvroUtil.getAvroSchema(meta, new TajoConf()); assertEquals(expected, schema); meta = CatalogUtil.newTableMeta("AVRO"); meta.putOption(StorageConstants.AVRO_SCHEMA_URL, schemaUrl.getPath()); schema = AvroUtil.getAvroSchema(meta, new TajoConf()); assertEquals(expected, schema); HttpFileServer server = new HttpFileServer(NetUtils.createSocketAddr("127.0.0.1:0")); try { server.start(); InetSocketAddress addr = server.getBindAddress(); String url = "http: meta = CatalogUtil.newTableMeta("AVRO"); meta.putOption(StorageConstants.AVRO_SCHEMA_URL, url); schema = AvroUtil.getAvroSchema(meta, new TajoConf()); } finally { server.stop(); } assertEquals(expected, schema); }