@Test public void testListTables() throws Exception { Configuration conf = new Configuration(); String warehousePath = temp.newFolder().getAbsolutePath(); HadoopCatalog catalog = new HadoopCatalog(conf, warehousePath); TableIdentifier tbl1 = TableIdentifier.of("db", "tbl1"); TableIdentifier tbl2 = TableIdentifier.of("db", "tbl2"); TableIdentifier tbl3 = TableIdentifier.of("db", "ns1", "tbl3"); TableIdentifier tbl4 = TableIdentifier.of("db", "metadata", "metadata"); Lists.newArrayList(tbl1, tbl2, tbl3, tbl4).forEach(t -> catalog.createTable(t, SCHEMA, PartitionSpec.unpartitioned()) ); List<TableIdentifier> tbls1 = catalog.listTables(Namespace.of("db")); Set<String> tblSet = Sets.newHashSet(tbls1.stream().map(t -> t.name()).iterator()); Assert.assertEquals(tblSet.size(), 2); Assert.assertTrue(tblSet.contains("tbl1")); Assert.assertTrue(tblSet.contains("tbl2")); List<TableIdentifier> tbls2 = catalog.listTables(Namespace.of("db", "ns1")); Assert.assertEquals(tbls2.size(), 1); Assert.assertTrue(tbls2.get(0).name().equals("tbl3")); AssertHelpers.assertThrows("should throw exception", NoSuchNamespaceException.class, "Namespace does not exist: ", () -> { catalog.listTables(Namespace.of("db", "ns1", "ns2")); }); }
@Override public List<TableIdentifier> listTables(Namespace namespace) { Preconditions.checkArgument(namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace); Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); Set<TableIdentifier> tblIdents = Sets.newHashSet(); try { if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) { throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } for (FileStatus s : fs.listStatus(nsPath)) { Path path = s.getPath(); if (!fs.isDirectory(path)) { continue; } Path metadataPath = new Path(path, "metadata"); if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) && (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) { TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName()); tblIdents.add(tblIdent); } } } catch (IOException ioe) { throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace); } return Lists.newArrayList(tblIdents); }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public List<TableIdentifier> listTables(Namespace namespace) { Preconditions.checkArgument(namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace); Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); Set<TableIdentifier> tblIdents = Sets.newHashSet(); try { if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) { throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } for (FileStatus s : fs.listStatus(nsPath)) { Path path = s.getPath(); if (!fs.isDirectory(path)) { continue; } Path metadataPath = new Path(path, "metadata"); if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) && (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) { TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName()); tblIdents.add(tblIdent); } } } catch (IOException ioe) { throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace); } return Lists.newArrayList(tblIdents); } }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public List<TableIdentifier> listTables(Namespace namespace) { Preconditions.checkArgument(namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace); Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); Set<TableIdentifier> tblIdents = Sets.newHashSet(); try { if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) { throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } for (FileStatus s : fs.listStatus(nsPath)) { Path path = s.getPath(); if (!fs.isDirectory(path)) { continue; } Path metadataPath = new Path(path, "metadata"); if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) && (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) { TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName()); tblIdents.add(tblIdent); } } } catch (IOException ioe) { throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace); } return Lists.newArrayList(tblIdents); } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public List<TableIdentifier> listTables(Namespace namespace) { Preconditions.checkArgument(namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace); Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); Set<TableIdentifier> tblIdents = Sets.newHashSet(); try { if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) { throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } for (FileStatus s : fs.listStatus(nsPath)) { Path path = s.getPath(); if (!fs.isDirectory(path)) { continue; } Path metadataPath = new Path(path, "metadata"); if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) && (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) { TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName()); tblIdents.add(tblIdent); } } } catch (IOException ioe) { throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace); } return Lists.newArrayList(tblIdents); } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override Table createTable(
      TableIdentifier identifier, Schema schema, PartitionSpec spec, String location, Map<String, String> properties); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier to); @Override void createNamespace(Namespace namespace, Map<String, String> meta); @Override List<Namespace> listNamespaces(Namespace namespace); @Override boolean dropNamespace(Namespace namespace); @Override boolean setProperties(Namespace namespace,  Map<String, String> properties); @Override boolean removeProperties(Namespace namespace,  Set<String> properties); @Override Map<String, String> loadNamespaceMetadata(Namespace namespace); @Override void close(); }
HadoopCatalog extends BaseMetastoreCatalog implements Closeable, SupportsNamespaces { @Override public List<TableIdentifier> listTables(Namespace namespace) { Preconditions.checkArgument(namespace.levels().length >= 1, "Missing database in table identifier: %s", namespace); Path nsPath = new Path(warehouseLocation, SLASH.join(namespace.levels())); Set<TableIdentifier> tblIdents = Sets.newHashSet(); try { if (!fs.exists(nsPath) || !fs.isDirectory(nsPath)) { throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } for (FileStatus s : fs.listStatus(nsPath)) { Path path = s.getPath(); if (!fs.isDirectory(path)) { continue; } Path metadataPath = new Path(path, "metadata"); if (fs.exists(metadataPath) && fs.isDirectory(metadataPath) && (fs.listStatus(metadataPath, TABLE_FILTER).length >= 1)) { TableIdentifier tblIdent = TableIdentifier.of(namespace, path.getName()); tblIdents.add(tblIdent); } } } catch (IOException ioe) { throw new RuntimeIOException(ioe, "Failed to list tables under: %s", namespace); } return Lists.newArrayList(tblIdents); } HadoopCatalog(String name, Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf, String warehouseLocation);  HadoopCatalog(Configuration conf); @Override List<TableIdentifier> listTables(Namespace namespace); @Override Table createTable(
      TableIdentifier identifier, Schema schema, PartitionSpec spec, String location, Map<String, String> properties); @Override boolean dropTable(TableIdentifier identifier, boolean purge); @Override void renameTable(TableIdentifier from, TableIdentifier to); @Override void createNamespace(Namespace namespace, Map<String, String> meta); @Override List<Namespace> listNamespaces(Namespace namespace); @Override boolean dropNamespace(Namespace namespace); @Override boolean setProperties(Namespace namespace,  Map<String, String> properties); @Override boolean removeProperties(Namespace namespace,  Set<String> properties); @Override Map<String, String> loadNamespaceMetadata(Namespace namespace); @Override void close();  }