test_class.file: legacy/src/test/java/macrobase/ingest/SQLIngesterTest.java
test_class.identifier: SQLIngesterTest
test_case.body: @Test
      public void testGetRows() throws Exception {
          JDBCMockObjectFactory factory = new JDBCMockObjectFactory();
          factory.registerMockDriver();
          MockConnection connection = factory.getMockConnection();
          StatementResultSetHandler statementHandler =
                  connection.getStatementResultSetHandler();
          MockResultSet result = statementHandler.createResultSet();
  
          MockResultSetMetaData metaData = new MockResultSetMetaData();
  
          List<Integer> fakeData = new ArrayList<>();
  
          final int NUM_ROWS = 100;
          final int NUM_ATTRS = 5;
          final int NUM_HIGH = 2;
          final int NUM_LOW = 3;
          final int NUM_AUXILIARY = 1;
  
          final int DIMENSION = NUM_ATTRS + NUM_HIGH + NUM_LOW + NUM_AUXILIARY;
  
          Integer val = 1;
          for(int rno = 0; rno < NUM_ROWS; ++rno) {
              List<Object> rowString = new ArrayList<>();
              for(Integer i = 0; i < DIMENSION; ++i) {
                  rowString.add(val.toString());
                  val++;
              }
              result.addRow(rowString);
          }
  
          int column = 1;
          List<String> attributes = new ArrayList<>();
          for(int i = 0; i < NUM_ATTRS; ++i) {
              String attrName = String.format("attr%d", i);
              metaData.setColumnName(column, attrName);
              attributes.add(attrName);
              column++;
          }
  
          List<String> lowMetrics = new ArrayList<>();
          for(int i = 0; i < NUM_LOW; ++i) {
              String metricName = String.format("lowMetric%d", i);
              metaData.setColumnName(column, metricName);
              lowMetrics.add(metricName);
              column++;
          }
  
          List<String> highMetrics = new ArrayList<>();
          for(int i = 0; i < NUM_HIGH; ++i) {
              String metricName = String.format("highMetric%d", i);
              metaData.setColumnName(column, metricName);
              highMetrics.add(metricName);
              column++;
          }
  
          metaData.setColumnCount(DIMENSION);
  
          result.setResultSetMetaData(metaData);
  
          statementHandler.prepareGlobalResultSet(result);
  
          List<String> allMetrics = new ArrayList<>();
          allMetrics.addAll(lowMetrics);
          allMetrics.addAll(highMetrics);
  
          MacroBaseConf conf = new MacroBaseConf();
          conf.set(MacroBaseConf.ATTRIBUTES, attributes);
          conf.set(MacroBaseConf.METRICS, allMetrics);
          conf.set(MacroBaseConf.BASE_QUERY, "SELECT * FROM test LIMIT 10000;");
  
          SQLIngester loader = new TestSQLIngester(conf, connection);
          loader.connect();
  
          Map<String, String> preds = new HashMap<>();
  
          preds.put("c1", "v1");
  
          RowSet rs = loader.getRows(conf.getString(MacroBaseConf.BASE_QUERY),
                                         preds,
                                         100,
                                         1000);
  
          assertEquals(NUM_ROWS, rs.getRows().size());
  
          int curVal = 1;
          for (RowSet.Row r : rs.getRows()) {
              for(ColumnValue cv : r.getColumnValues()) {
                  assertEquals(curVal, Integer.parseInt(cv.getValue()));
                  curVal++;
              }
          }
      }
test_case.class_method_signature: SQLIngesterTest.testGetRows()
test_case.full_signature: @Test public void testGetRows()
test_case.identifier: testGetRows
test_case.invocations: registerMockDriver getMockConnection getStatementResultSetHandler createResultSet add toString addRow format setColumnName add format setColumnName add format setColumnName add setColumnCount setResultSetMetaData prepareGlobalResultSet addAll addAll set set set connect put getRows getString assertEquals size getRows getRows getColumnValues assertEquals parseInt getValue
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testGetRows()
focal_class.declarator: log = LoggerFactory.getLogger(SQLIngester.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(SQLIngester.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: source
focal_class.modifier: private
focal_class.original_string: private ManagedDataSource source;
focal_class.type: ManagedDataSource
focal_class.var_name: source
focal_class.declarator: connection
focal_class.modifier: private
focal_class.original_string: private Connection connection;
focal_class.type: Connection
focal_class.var_name: connection
focal_class.declarator: dbUrl
focal_class.modifier: private final
focal_class.original_string: private final String dbUrl;
focal_class.type: String
focal_class.var_name: dbUrl
focal_class.declarator: dbUser
focal_class.modifier: private final
focal_class.original_string: private final String dbUser;
focal_class.type: String
focal_class.var_name: dbUser
focal_class.declarator: dbPassword
focal_class.modifier: private final
focal_class.original_string: private final String dbPassword;
focal_class.type: String
focal_class.var_name: dbPassword
focal_class.declarator: dbName
focal_class.modifier: private final
focal_class.original_string: private final String dbName;
focal_class.type: String
focal_class.var_name: dbName
focal_class.declarator: timeColumn
focal_class.modifier: private final
focal_class.original_string: private final Integer timeColumn;
focal_class.type: Integer
focal_class.var_name: timeColumn
focal_class.declarator: baseQuery
focal_class.modifier: protected final
focal_class.original_string: protected final String baseQuery;
focal_class.type: String
focal_class.var_name: baseQuery
focal_class.declarator: resultSet
focal_class.modifier: protected
focal_class.original_string: protected ResultSet resultSet;
focal_class.type: ResultSet
focal_class.var_name: resultSet
focal_class.declarator: output = new MBStream<>()
focal_class.modifier: private final
focal_class.original_string: private final MBStream<Datum> output = new MBStream<>();
focal_class.type: MBStream<Datum>
focal_class.var_name: output
focal_class.declarator: connected = false
focal_class.modifier: private
focal_class.original_string: private boolean connected = false;
focal_class.type: boolean
focal_class.var_name: connected
focal_class.declarator: LIMIT_REGEX = "(LIMIT\\s\\d+)"
focal_class.modifier: private static final
focal_class.original_string: private static final String LIMIT_REGEX = "(LIMIT\\s\\d+)";
focal_class.type: String
focal_class.var_name: LIMIT_REGEX
focal_class.file: legacy/src/main/java/macrobase/ingest/SQLIngester.java
focal_class.identifier: SQLIngester
focal_class.class_method_signature: SQLIngester.getDriverClass()
focal_class.full_signature: abstract public String getDriverClass()
focal_class.identifier: getDriverClass
focal_class.modifiers: abstract public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getDriverClass()
focal_class.class_method_signature: SQLIngester.getJDBCUrlPrefix()
focal_class.full_signature: abstract public String getJDBCUrlPrefix()
focal_class.identifier: getJDBCUrlPrefix
focal_class.modifiers: abstract public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getJDBCUrlPrefix()
focal_class.class_method_signature: SQLIngester.SQLIngester(MacroBaseConf conf)
focal_class.full_signature: public  SQLIngester(MacroBaseConf conf)
focal_class.identifier: SQLIngester
focal_class.modifiers: public
focal_class.parameters: (MacroBaseConf conf)
focal_class.signature:  SQLIngester(MacroBaseConf conf)
focal_class.class_method_signature: SQLIngester.SQLIngester(MacroBaseConf conf, Connection connection)
focal_class.full_signature: public  SQLIngester(MacroBaseConf conf, Connection connection)
focal_class.identifier: SQLIngester
focal_class.modifiers: public
focal_class.parameters: (MacroBaseConf conf, Connection connection)
focal_class.signature:  SQLIngester(MacroBaseConf conf, Connection connection)
focal_class.class_method_signature: SQLIngester.connect()
focal_class.full_signature: public void connect()
focal_class.identifier: connect
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void connect()
focal_class.class_method_signature: SQLIngester.getJDBCProperties()
focal_class.full_signature: protected Map<String, String> getJDBCProperties()
focal_class.identifier: getJDBCProperties
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.return: Map<String, String>
focal_class.signature: Map<String, String> getJDBCProperties()
focal_class.class_method_signature: SQLIngester.removeLimit(String sql)
focal_class.full_signature: private String removeLimit(String sql)
focal_class.identifier: removeLimit
focal_class.modifiers: private
focal_class.parameters: (String sql)
focal_class.return: String
focal_class.signature: String removeLimit(String sql)
focal_class.class_method_signature: SQLIngester.removeSqlJunk(String sql)
focal_class.full_signature: private String removeSqlJunk(String sql)
focal_class.identifier: removeSqlJunk
focal_class.modifiers: private
focal_class.parameters: (String sql)
focal_class.return: String
focal_class.signature: String removeSqlJunk(String sql)
focal_class.class_method_signature: SQLIngester.getSchema(String baseQuery)
focal_class.full_signature: public Schema getSchema(String baseQuery)
focal_class.identifier: getSchema
focal_class.modifiers: public
focal_class.parameters: (String baseQuery)
focal_class.return: Schema
focal_class.signature: Schema getSchema(String baseQuery)
focal_class.class_method_signature: SQLIngester.getRowsSql(String baseQuery,
                               Map<String, String> preds,
                               int limit,
                               int offset)
focal_class.full_signature: public String getRowsSql(String baseQuery,
                               Map<String, String> preds,
                               int limit,
                               int offset)
focal_class.identifier: getRowsSql
focal_class.modifiers: public
focal_class.parameters: (String baseQuery,
                               Map<String, String> preds,
                               int limit,
                               int offset)
focal_class.return: String
focal_class.signature: String getRowsSql(String baseQuery,
                               Map<String, String> preds,
                               int limit,
                               int offset)
focal_class.class_method_signature: SQLIngester.getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_class.full_signature: @Override public RowSet getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_class.identifier: getRows
focal_class.modifiers: @Override public
focal_class.parameters: (String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_class.return: RowSet
focal_class.signature: RowSet getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_class.class_method_signature: SQLIngester.initializeConnection()
focal_class.full_signature: private void initializeConnection()
focal_class.identifier: initializeConnection
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void initializeConnection()
focal_class.class_method_signature: SQLIngester.initializeResultSet()
focal_class.full_signature: private void initializeResultSet()
focal_class.identifier: initializeResultSet
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void initializeResultSet()
focal_class.class_method_signature: SQLIngester.getStream()
focal_class.full_signature: @Override public MBStream<Datum> getStream()
focal_class.identifier: getStream
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: MBStream<Datum>
focal_class.signature: MBStream<Datum> getStream()
focal_class.class_method_signature: SQLIngester.getNext()
focal_class.full_signature: private Datum getNext()
focal_class.identifier: getNext
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Datum
focal_class.signature: Datum getNext()
focal_class.class_method_signature: SQLIngester.getAttrs(ResultSet rs, DatumEncoder encoder, int rsStartIndex)
focal_class.full_signature: private List<Integer> getAttrs(ResultSet rs, DatumEncoder encoder, int rsStartIndex)
focal_class.identifier: getAttrs
focal_class.modifiers: private
focal_class.parameters: (ResultSet rs, DatumEncoder encoder, int rsStartIndex)
focal_class.return: List<Integer>
focal_class.signature: List<Integer> getAttrs(ResultSet rs, DatumEncoder encoder, int rsStartIndex)
focal_class.class_method_signature: SQLIngester.getMetrics(ResultSet rs, int rsStartIndex)
focal_class.full_signature: private RealVector getMetrics(ResultSet rs, int rsStartIndex)
focal_class.identifier: getMetrics
focal_class.modifiers: private
focal_class.parameters: (ResultSet rs, int rsStartIndex)
focal_class.return: RealVector
focal_class.signature: RealVector getMetrics(ResultSet rs, int rsStartIndex)
focal_class.class_method_signature: SQLIngester.orderByTimeColumn(String sql, @Nullable Integer timeColumn)
focal_class.full_signature: private String orderByTimeColumn(String sql, @Nullable Integer timeColumn)
focal_class.identifier: orderByTimeColumn
focal_class.modifiers: private
focal_class.parameters: (String sql, @Nullable Integer timeColumn)
focal_class.return: String
focal_class.signature: String orderByTimeColumn(String sql, @Nullable Integer timeColumn)
focal_class.superclass: extends DataIngester
focal_method.body: @Override
      public RowSet getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset) throws SQLException {
          initializeConnection();
          // TODO handle time column here
  
          Statement stmt = connection.createStatement();
          ResultSet rs = stmt.executeQuery(getRowsSql(baseQuery, preds, limit, offset));
  
          List<RowSet.Row> rows = Lists.newArrayList();
          while (rs.next()) {
              List<ColumnValue> columnValues = Lists.newArrayList();
  
              for (int i = 1; i <= rs.getMetaData().getColumnCount(); ++i) {
                  columnValues.add(
                          new ColumnValue(rs.getMetaData().getColumnName(i),
                                  rs.getString(i)));
              }
              rows.add(new RowSet.Row(columnValues));
          }
  
          return new RowSet(rows);
      }
focal_method.class_method_signature: SQLIngester.getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_method.full_signature: @Override public RowSet getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_method.identifier: getRows
focal_method.invocations: initializeConnection createStatement executeQuery getRowsSql newArrayList next newArrayList getColumnCount getMetaData add getColumnName getMetaData getString add
focal_method.modifiers: @Override public
focal_method.parameters: (String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)
focal_method.return: RowSet
focal_method.signature: RowSet getRows(String baseQuery,
                            Map<String, String> preds,
                            int limit,
                            int offset)