@Test public void invalidTableName() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("\"t.r.o.u.b.l.e.m.a.k.e.r\" is not a valid Hive table name. Should be either <table_name> or <db_name.table_name>"); IMetaStoreClient metaStoreClient = mock(IMetaStoreClient.class); hiveClientWrapper.extractTablesFromPattern(metaStoreClient, "t.r.o.u.b.l.e.m.a.k.e.r"); }
public List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern) { String dbPattern, tablePattern; String errorMsg = " is not a valid Hive table name. " + "Should be either <table_name> or <db_name.table_name>"; if (StringUtils.isBlank(pattern)) { throw new IllegalArgumentException("empty string" + errorMsg); } String[] rawTokens = pattern.split("[.]"); ArrayList<String> tokens = new ArrayList<>(); for (String tok : rawTokens) { if (StringUtils.isBlank(tok)) { continue; } tokens.add(tok.trim()); } if (tokens.size() == 1) { dbPattern = MetaStoreUtils.DEFAULT_DATABASE_NAME; tablePattern = tokens.get(0); } else if (tokens.size() == 2) { dbPattern = tokens.get(0); tablePattern = tokens.get(1); } else { throw new IllegalArgumentException("\"" + pattern + "\"" + errorMsg); } return getTablesFromPattern(client, dbPattern, tablePattern); }
HiveClientWrapper { public List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern) { String dbPattern, tablePattern; String errorMsg = " is not a valid Hive table name. " + "Should be either <table_name> or <db_name.table_name>"; if (StringUtils.isBlank(pattern)) { throw new IllegalArgumentException("empty string" + errorMsg); } String[] rawTokens = pattern.split("[.]"); ArrayList<String> tokens = new ArrayList<>(); for (String tok : rawTokens) { if (StringUtils.isBlank(tok)) { continue; } tokens.add(tok.trim()); } if (tokens.size() == 1) { dbPattern = MetaStoreUtils.DEFAULT_DATABASE_NAME; tablePattern = tokens.get(0); } else if (tokens.size() == 2) { dbPattern = tokens.get(0); tablePattern = tokens.get(1); } else { throw new IllegalArgumentException("\"" + pattern + "\"" + errorMsg); } return getTablesFromPattern(client, dbPattern, tablePattern); } }
HiveClientWrapper { public List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern) { String dbPattern, tablePattern; String errorMsg = " is not a valid Hive table name. " + "Should be either <table_name> or <db_name.table_name>"; if (StringUtils.isBlank(pattern)) { throw new IllegalArgumentException("empty string" + errorMsg); } String[] rawTokens = pattern.split("[.]"); ArrayList<String> tokens = new ArrayList<>(); for (String tok : rawTokens) { if (StringUtils.isBlank(tok)) { continue; } tokens.add(tok.trim()); } if (tokens.size() == 1) { dbPattern = MetaStoreUtils.DEFAULT_DATABASE_NAME; tablePattern = tokens.get(0); } else if (tokens.size() == 2) { dbPattern = tokens.get(0); tablePattern = tokens.get(1); } else { throw new IllegalArgumentException("\"" + pattern + "\"" + errorMsg); } return getTablesFromPattern(client, dbPattern, tablePattern); } private  HiveClientWrapper();   HiveClientWrapper(HiveClientFactory hiveClientFactory); }
HiveClientWrapper { public List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern) { String dbPattern, tablePattern; String errorMsg = " is not a valid Hive table name. " + "Should be either <table_name> or <db_name.table_name>"; if (StringUtils.isBlank(pattern)) { throw new IllegalArgumentException("empty string" + errorMsg); } String[] rawTokens = pattern.split("[.]"); ArrayList<String> tokens = new ArrayList<>(); for (String tok : rawTokens) { if (StringUtils.isBlank(tok)) { continue; } tokens.add(tok.trim()); } if (tokens.size() == 1) { dbPattern = MetaStoreUtils.DEFAULT_DATABASE_NAME; tablePattern = tokens.get(0); } else if (tokens.size() == 2) { dbPattern = tokens.get(0); tablePattern = tokens.get(1); } else { throw new IllegalArgumentException("\"" + pattern + "\"" + errorMsg); } return getTablesFromPattern(client, dbPattern, tablePattern); } private  HiveClientWrapper();   HiveClientWrapper(HiveClientFactory hiveClientFactory); static HiveClientWrapper getInstance(); IMetaStoreClient initHiveClient(RequestContext context, Configuration configuration); Table getHiveTable(IMetaStoreClient client, Metadata.Item itemName); void getSchema(Table tbl, Metadata metadata); byte[] makeUserData(String fragmenterClassName,
                               HiveTablePartition partData,
                               boolean filterInFragmenter,
                               List<Integer> hiveIndexes,
                               String allColumnNames,
                               String allColumnTypes); Metadata.Item extractTableFromName(String qualifiedName); boolean hasComplexTypes(Metadata metadata); List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern); Integer getDelimiterCode(StorageDescriptor sd); }
HiveClientWrapper { public List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern) { String dbPattern, tablePattern; String errorMsg = " is not a valid Hive table name. " + "Should be either <table_name> or <db_name.table_name>"; if (StringUtils.isBlank(pattern)) { throw new IllegalArgumentException("empty string" + errorMsg); } String[] rawTokens = pattern.split("[.]"); ArrayList<String> tokens = new ArrayList<>(); for (String tok : rawTokens) { if (StringUtils.isBlank(tok)) { continue; } tokens.add(tok.trim()); } if (tokens.size() == 1) { dbPattern = MetaStoreUtils.DEFAULT_DATABASE_NAME; tablePattern = tokens.get(0); } else if (tokens.size() == 2) { dbPattern = tokens.get(0); tablePattern = tokens.get(1); } else { throw new IllegalArgumentException("\"" + pattern + "\"" + errorMsg); } return getTablesFromPattern(client, dbPattern, tablePattern); } private  HiveClientWrapper();   HiveClientWrapper(HiveClientFactory hiveClientFactory); static HiveClientWrapper getInstance(); IMetaStoreClient initHiveClient(RequestContext context, Configuration configuration); Table getHiveTable(IMetaStoreClient client, Metadata.Item itemName); void getSchema(Table tbl, Metadata metadata); byte[] makeUserData(String fragmenterClassName,
                               HiveTablePartition partData,
                               boolean filterInFragmenter,
                               List<Integer> hiveIndexes,
                               String allColumnNames,
                               String allColumnTypes); Metadata.Item extractTableFromName(String qualifiedName); boolean hasComplexTypes(Metadata metadata); List<Metadata.Item> extractTablesFromPattern(IMetaStoreClient client, String pattern); Integer getDelimiterCode(StorageDescriptor sd);  }