@Test public void getTableMetadataView() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Hive views are not supported by PXF"); String tableName = "cause"; fetcher = new HiveMetadataFetcher(context, mockConfigurationFactory, fakeHiveClientWrapper); Table hiveTable = new Table(); hiveTable.setTableType("VIRTUAL_VIEW"); when(mockHiveClient.getTable("default", tableName)).thenReturn(hiveTable); metadataList = fetcher.getMetadata(tableName); }
@Override public List<Metadata> getMetadata(String pattern) throws Exception { boolean ignoreErrors = false; List<Metadata.Item> tblsDesc = hiveClientWrapper.extractTablesFromPattern(client, pattern); if (tblsDesc == null || tblsDesc.isEmpty()) { LOG.warn("No tables found for the given pattern: " + pattern); return null; } List<Metadata> metadataList = new ArrayList<>(); if (tblsDesc.size() > 1) { ignoreErrors = true; } for (Metadata.Item tblDesc : tblsDesc) { try { Metadata metadata = new Metadata(tblDesc); Table tbl = hiveClientWrapper.getHiveTable(client, tblDesc); hiveClientWrapper.getSchema(tbl, metadata); boolean hasComplexTypes = hiveClientWrapper.hasComplexTypes(metadata); metadataList.add(metadata); List<Partition> tablePartitions = client.listPartitionsByFilter(tblDesc.getPath(), tblDesc.getName(), "", (short) -1); Set<OutputFormat> formats = new HashSet<>(); for (Partition tablePartition : tablePartitions) { String inputFormat = tablePartition.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } if (tablePartitions.size() == 0) { String inputFormat = tbl.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } metadata.setOutputFormats(formats); Map<String, String> outputParameters = new HashMap<>(); Integer delimiterCode = hiveClientWrapper.getDelimiterCode(tbl.getSd()); outputParameters.put(DELIM_FIELD, delimiterCode.toString()); metadata.setOutputParameters(outputParameters); } catch (UnsupportedTypeException | UnsupportedOperationException e) { if (ignoreErrors) { LOG.warn("Metadata fetch for " + tblDesc.toString() + " failed. " + e.getMessage()); } else { throw e; } } } return metadataList; }
HiveMetadataFetcher extends BasePlugin implements MetadataFetcher { @Override public List<Metadata> getMetadata(String pattern) throws Exception { boolean ignoreErrors = false; List<Metadata.Item> tblsDesc = hiveClientWrapper.extractTablesFromPattern(client, pattern); if (tblsDesc == null || tblsDesc.isEmpty()) { LOG.warn("No tables found for the given pattern: " + pattern); return null; } List<Metadata> metadataList = new ArrayList<>(); if (tblsDesc.size() > 1) { ignoreErrors = true; } for (Metadata.Item tblDesc : tblsDesc) { try { Metadata metadata = new Metadata(tblDesc); Table tbl = hiveClientWrapper.getHiveTable(client, tblDesc); hiveClientWrapper.getSchema(tbl, metadata); boolean hasComplexTypes = hiveClientWrapper.hasComplexTypes(metadata); metadataList.add(metadata); List<Partition> tablePartitions = client.listPartitionsByFilter(tblDesc.getPath(), tblDesc.getName(), "", (short) -1); Set<OutputFormat> formats = new HashSet<>(); for (Partition tablePartition : tablePartitions) { String inputFormat = tablePartition.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } if (tablePartitions.size() == 0) { String inputFormat = tbl.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } metadata.setOutputFormats(formats); Map<String, String> outputParameters = new HashMap<>(); Integer delimiterCode = hiveClientWrapper.getDelimiterCode(tbl.getSd()); outputParameters.put(DELIM_FIELD, delimiterCode.toString()); metadata.setOutputParameters(outputParameters); } catch (UnsupportedTypeException | UnsupportedOperationException e) { if (ignoreErrors) { LOG.warn("Metadata fetch for " + tblDesc.toString() + " failed. " + e.getMessage()); } else { throw e; } } } return metadataList; } }
HiveMetadataFetcher extends BasePlugin implements MetadataFetcher { @Override public List<Metadata> getMetadata(String pattern) throws Exception { boolean ignoreErrors = false; List<Metadata.Item> tblsDesc = hiveClientWrapper.extractTablesFromPattern(client, pattern); if (tblsDesc == null || tblsDesc.isEmpty()) { LOG.warn("No tables found for the given pattern: " + pattern); return null; } List<Metadata> metadataList = new ArrayList<>(); if (tblsDesc.size() > 1) { ignoreErrors = true; } for (Metadata.Item tblDesc : tblsDesc) { try { Metadata metadata = new Metadata(tblDesc); Table tbl = hiveClientWrapper.getHiveTable(client, tblDesc); hiveClientWrapper.getSchema(tbl, metadata); boolean hasComplexTypes = hiveClientWrapper.hasComplexTypes(metadata); metadataList.add(metadata); List<Partition> tablePartitions = client.listPartitionsByFilter(tblDesc.getPath(), tblDesc.getName(), "", (short) -1); Set<OutputFormat> formats = new HashSet<>(); for (Partition tablePartition : tablePartitions) { String inputFormat = tablePartition.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } if (tablePartitions.size() == 0) { String inputFormat = tbl.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } metadata.setOutputFormats(formats); Map<String, String> outputParameters = new HashMap<>(); Integer delimiterCode = hiveClientWrapper.getDelimiterCode(tbl.getSd()); outputParameters.put(DELIM_FIELD, delimiterCode.toString()); metadata.setOutputParameters(outputParameters); } catch (UnsupportedTypeException | UnsupportedOperationException e) { if (ignoreErrors) { LOG.warn("Metadata fetch for " + tblDesc.toString() + " failed. " + e.getMessage()); } else { throw e; } } } return metadataList; } HiveMetadataFetcher(RequestContext context);   HiveMetadataFetcher(RequestContext context, ConfigurationFactory configurationFactory, HiveClientWrapper hiveClientWrapper); }
HiveMetadataFetcher extends BasePlugin implements MetadataFetcher { @Override public List<Metadata> getMetadata(String pattern) throws Exception { boolean ignoreErrors = false; List<Metadata.Item> tblsDesc = hiveClientWrapper.extractTablesFromPattern(client, pattern); if (tblsDesc == null || tblsDesc.isEmpty()) { LOG.warn("No tables found for the given pattern: " + pattern); return null; } List<Metadata> metadataList = new ArrayList<>(); if (tblsDesc.size() > 1) { ignoreErrors = true; } for (Metadata.Item tblDesc : tblsDesc) { try { Metadata metadata = new Metadata(tblDesc); Table tbl = hiveClientWrapper.getHiveTable(client, tblDesc); hiveClientWrapper.getSchema(tbl, metadata); boolean hasComplexTypes = hiveClientWrapper.hasComplexTypes(metadata); metadataList.add(metadata); List<Partition> tablePartitions = client.listPartitionsByFilter(tblDesc.getPath(), tblDesc.getName(), "", (short) -1); Set<OutputFormat> formats = new HashSet<>(); for (Partition tablePartition : tablePartitions) { String inputFormat = tablePartition.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } if (tablePartitions.size() == 0) { String inputFormat = tbl.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } metadata.setOutputFormats(formats); Map<String, String> outputParameters = new HashMap<>(); Integer delimiterCode = hiveClientWrapper.getDelimiterCode(tbl.getSd()); outputParameters.put(DELIM_FIELD, delimiterCode.toString()); metadata.setOutputParameters(outputParameters); } catch (UnsupportedTypeException | UnsupportedOperationException e) { if (ignoreErrors) { LOG.warn("Metadata fetch for " + tblDesc.toString() + " failed. " + e.getMessage()); } else { throw e; } } } return metadataList; } HiveMetadataFetcher(RequestContext context);   HiveMetadataFetcher(RequestContext context, ConfigurationFactory configurationFactory, HiveClientWrapper hiveClientWrapper); @Override List<Metadata> getMetadata(String pattern); }
HiveMetadataFetcher extends BasePlugin implements MetadataFetcher { @Override public List<Metadata> getMetadata(String pattern) throws Exception { boolean ignoreErrors = false; List<Metadata.Item> tblsDesc = hiveClientWrapper.extractTablesFromPattern(client, pattern); if (tblsDesc == null || tblsDesc.isEmpty()) { LOG.warn("No tables found for the given pattern: " + pattern); return null; } List<Metadata> metadataList = new ArrayList<>(); if (tblsDesc.size() > 1) { ignoreErrors = true; } for (Metadata.Item tblDesc : tblsDesc) { try { Metadata metadata = new Metadata(tblDesc); Table tbl = hiveClientWrapper.getHiveTable(client, tblDesc); hiveClientWrapper.getSchema(tbl, metadata); boolean hasComplexTypes = hiveClientWrapper.hasComplexTypes(metadata); metadataList.add(metadata); List<Partition> tablePartitions = client.listPartitionsByFilter(tblDesc.getPath(), tblDesc.getName(), "", (short) -1); Set<OutputFormat> formats = new HashSet<>(); for (Partition tablePartition : tablePartitions) { String inputFormat = tablePartition.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } if (tablePartitions.size() == 0) { String inputFormat = tbl.getSd().getInputFormat(); OutputFormat outputFormat = getOutputFormat(inputFormat, hasComplexTypes); formats.add(outputFormat); } metadata.setOutputFormats(formats); Map<String, String> outputParameters = new HashMap<>(); Integer delimiterCode = hiveClientWrapper.getDelimiterCode(tbl.getSd()); outputParameters.put(DELIM_FIELD, delimiterCode.toString()); metadata.setOutputParameters(outputParameters); } catch (UnsupportedTypeException | UnsupportedOperationException e) { if (ignoreErrors) { LOG.warn("Metadata fetch for " + tblDesc.toString() + " failed. " + e.getMessage()); } else { throw e; } } } return metadataList; } HiveMetadataFetcher(RequestContext context);   HiveMetadataFetcher(RequestContext context, ConfigurationFactory configurationFactory, HiveClientWrapper hiveClientWrapper); @Override List<Metadata> getMetadata(String pattern);  }