SQLIngester extends DataIngester { public Schema getSchema(String baseQuery) throws SQLException { initializeConnection(); Statement stmt = connection.createStatement(); String sql = String.format("%s LIMIT 1", removeSqlJunk(removeLimit(baseQuery))); ResultSet rs = stmt.executeQuery(sql); List<Schema.SchemaColumn> columns = Lists.newArrayList(); for (int i = 1; i <= rs.getMetaData().getColumnCount(); ++i) { columns.add(new Schema.SchemaColumn(rs.getMetaData().getColumnName(i), rs.getMetaData().getColumnTypeName(i))); } return new Schema(columns); } SQLIngester(MacroBaseConf conf);  SQLIngester(MacroBaseConf conf, Connection connection); abstract String getDriverClass(); abstract String getJDBCUrlPrefix(); void connect(); Schema getSchema(String baseQuery); String getRowsSql(String baseQuery,
                             Map<String, String> preds,
                             int limit,
                             int offset); @Override RowSet getRows(String baseQuery,
                          Map<String, String> preds,
                          int limit,
                          int offset); @Override MBStream<Datum> getStream();  }
@Test public void testSchema() throws Exception { JDBCMockObjectFactory factory = new JDBCMockObjectFactory(); factory.registerMockDriver(); MockConnection connection = factory.getMockConnection(); StatementResultSetHandler statementHandler = connection.getStatementResultSetHandler(); MockResultSet result = statementHandler.createResultSet(); result.setFetchSize(0); MockResultSetMetaData metaData = new MockResultSetMetaData(); Map<String, String> fakeColumnMap = new HashMap<>(); fakeColumnMap.put("test1", "numeric"); fakeColumnMap.put("test2", "varchar"); fakeColumnMap.put("test3", "int8"); Set<String> fakeColumns = fakeColumnMap.keySet(); metaData.setColumnCount(fakeColumnMap.size()); int i = 1; for (Map.Entry<String, String> fc : fakeColumnMap.entrySet()) { metaData.setColumnName(i, fc.getKey()); metaData.setColumnTypeName(i, fc.getValue()); i++; } result.setResultSetMetaData(metaData); statementHandler.prepareGlobalResultSet(result); MacroBaseConf conf = new MacroBaseConf(); conf.set(MacroBaseConf.ATTRIBUTES, Lists.newArrayList(fakeColumns)); conf.set(MacroBaseConf.METRICS, new ArrayList<>()); conf.set(MacroBaseConf.BASE_QUERY, "SELECT * FROM test;"); SQLIngester loader = new TestSQLIngester(conf, connection); Schema schema = loader.getSchema("foo"); for (Schema.SchemaColumn sc : schema.getColumns()) { assertTrue(fakeColumns.contains(sc.getName())); assertEquals(fakeColumnMap.get(sc.getName()), sc.getType()); fakeColumns.remove(sc.getName()); } assertTrue(fakeColumns.isEmpty()); }