com.datastax.driver.core.ColumnDefinitions Java Examples

The following examples show how to use com.datastax.driver.core.ColumnDefinitions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraQuery.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Override
public void runPostQuery(Object result, XMLStreamWriter xmlWriter, InternalParamCollection params, int queryLevel)
        throws DataServiceFault {
    ResultSet rs = (ResultSet) result;
    if (this.hasResult()) {
        Iterator<Row> itr = rs.iterator();
        Row row;
        DataEntry dataEntry;
        ColumnDefinitions defs = rs.getColumnDefinitions();
        while (itr.hasNext()) {
            row = itr.next();
            dataEntry = this.getDataEntryFromRow(row, defs);
            this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
        }
    }
}
 
Example #2
Source File: SchemaStatement.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public SchemaStatement(Timer timer, StressSettings settings, DataSpec spec,
                       PreparedStatement statement, Integer thriftId, ConsistencyLevel cl, ValidationType validationType)
{
    super(timer, settings, spec);
    this.statement = statement;
    this.thriftId = thriftId;
    this.cl = cl;
    this.validationType = validationType;
    argumentIndex = new int[statement.getVariables().size()];
    bindBuffer = new Object[argumentIndex.length];
    int i = 0;
    for (ColumnDefinitions.Definition definition : statement.getVariables())
        argumentIndex[i++] = spec.partitionGenerator.indexOf(definition.getName());

    statement.setConsistencyLevel(JavaDriverClient.from(cl));
}
 
Example #3
Source File: CassandraIpcdDeviceDao.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private void parseOptimisticResult(ResultSet rs, String protocolAddress, UUID requiredPlace) throws IpcdDaoException {
   // not applied could imply that the device doesn't exist or the place didn't match
   if(!rs.wasApplied()) {
      Row r = rs.one();
      ColumnDefinitions colDef = r.getColumnDefinitions();

      if(colDef.contains(IpcdDeviceTable.Columns.PLACE_ID)) {
         // if the returned row contains a place id, the place id didn't match
         UUID actualPlaceId = r.getUUID(IpcdDeviceTable.Columns.PLACE_ID);
         if(!Objects.equal(requiredPlace, actualPlaceId)) {
            throw new PlaceMismatchException(requiredPlace, actualPlaceId);
         }
      }
      // special case for claiming device that is offline
      if(colDef.contains(IpcdDeviceTable.Columns.CONN_STATE) && IpcdDevice.ConnState.OFFLINE.name().equals(r.getString(IpcdDeviceTable.Columns.CONN_STATE))) {
         throw new DeviceNotFoundException(protocolAddress);
      }
      throw new DeviceNotFoundException(protocolAddress);
   }
}
 
Example #4
Source File: CqlMetaDaoImpl.java    From staash with Apache License 2.0 6 votes vote down vote up
private String convertResultSet(ResultSet rs) {
    // TODO Auto-generated method stub
    String colStr = "";
    String rowStr = "";
    JsonObject response = new JsonObject();
    List<Row> rows = rs.all();
    if (!rows.isEmpty() && rows.size() == 1) {
        rowStr = rows.get(0).toString();
    }
    ColumnDefinitions colDefs = rs.getColumnDefinitions();
    colStr = colDefs.toString();
    response.putString("columns", colStr.substring(8, colStr.length() - 1));
    response.putString("values", rowStr.substring(4, rowStr.length() - 1));
    return response.toString();

}
 
Example #5
Source File: CassandraFactory.java    From database-transform-tool with Apache License 2.0 6 votes vote down vote up
/**
 * 描述: 查询数据表字段名(key:字段名,value:字段类型名)
 * 时间: 2017年11月15日 上午11:29:32
 * @author yi.zhang
 * @param table	表名
 * @return
 */
public Map<String,String> queryColumns(String table){
	try {
		String sql = "select * from "+table;
		ResultSet rs = session.execute(sql);
		ColumnDefinitions rscd = rs.getColumnDefinitions();
		int count = rscd.size();
		Map<String,String> reflect = new HashMap<String,String>();
		for (int i = 0; i < count; i++) {
			String column = rscd.getName(i);
			String type = rscd.getType(i).getName().name().toLowerCase();
			reflect.put(column, type);
		}
		return reflect;
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
Example #6
Source File: RawMetricMapper.java    From realtime-analytics with GNU General Public License v2.0 6 votes vote down vote up
public RawNumericMetric map(Row row) {
    RawNumericMetric metricRow =  new RawNumericMetric(row.getString(0), row.getString(1), row.getDate(2).getTime(), row.getInt(3));
    ColumnDefinitions columeDef = row.getColumnDefinitions();
    List<Definition> columeDefList = columeDef.asList();
    Map<String, String> tagMap = new HashMap<String, String>();
    for(Definition def: columeDefList){
        if(def.getName().startsWith("tag_")){
            tagMap.put(def.getName(), row.getString(def.getName()));
        }
    }
    
    if(tagMap.size()>0){
        metricRow.setTagMap(tagMap);
    }
    return metricRow;
}
 
Example #7
Source File: CQL2CQL.java    From cqlkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void head(ColumnDefinitions columnDefinitions, PrintStream out) {
    template = commandLine.getOptionValue("T");
    if(template == null) {
        System.err.println("Template not specified");
        System.exit(1);
    }

    int matches = 0;
    Matcher matcher = pattern.matcher(template);
    while(matcher.find()) {
        matches++;
    }

    definitions = columnDefinitions.asList().toArray(new ColumnDefinitions.Definition[]{});

    if(matches != definitions.length) {
        System.err.printf("Template argument count mismtach! %d != %d\n",
                matches, definitions.length);
        System.exit(1);
    }
}
 
Example #8
Source File: DatabaseSpec.java    From bdt with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private void equalsColumns(ColumnDefinitions resCols, Map<String, String> dataTableColumns) {
    Iterator it = dataTableColumns.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        assertThat(resCols.toString()).as("The table not contains the column.").contains(e.getKey().toString());
        DataType type = resCols.getType(e.getKey().toString());
        assertThat(type.getName().toString()).as("The column type is not equals.").isEqualTo(e.getValue().toString());
    }
}
 
Example #9
Source File: DefinitionToNameFunction.java    From Explorer with Apache License 2.0 5 votes vote down vote up
/**
 * Extract name of columndefinions
 * @param definition Definition Objetc
 * @return name of definition
 */
@Override
public String transform(ColumnDefinitions.Definition definition) {
    String name = definition.getName();
    if (name==null)
        name="";
    return name;
}
 
Example #10
Source File: CassandraWriteMetrics.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private static @Nullable String getAgentRollupId(
        List<ColumnDefinitions.Definition> columnDefinitions, BoundStatement boundStatement) {
    ColumnDefinitions.Definition columnDefinition = columnDefinitions.get(0);
    String columnDefinitionName = columnDefinition.getName();
    if (columnDefinitionName.equals("agent_rollup_id")
            || columnDefinitionName.equals("agent_id")
            || columnDefinitionName.equals("agent_rollup")) {
        return boundStatement.getString(0);
    } else {
        return null;
    }
}
 
Example #11
Source File: CassandraWriteMetrics.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private @Nullable String getTransactionName(
        List<ColumnDefinitions.Definition> columnDefinitions, BoundStatement boundStatement) {
    if (columnDefinitions.size() < 3) {
        return currTransactionName.get();
    }
    ColumnDefinitions.Definition columnDefinition = columnDefinitions.get(2);
    String columnDefinitionName = columnDefinition.getName();
    if (columnDefinitionName.equals("transaction_name")) {
        return boundStatement.getString(2);
    } else {
        return currTransactionName.get();
    }
}
 
Example #12
Source File: CassandraWriteMetrics.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private @Nullable String getTransactionType(
        List<ColumnDefinitions.Definition> columnDefinitions, BoundStatement boundStatement) {
    if (columnDefinitions.size() < 2) {
        return currTransactionType.get();
    }
    ColumnDefinitions.Definition columnDefinition = columnDefinitions.get(1);
    String columnDefinitionName = columnDefinition.getName();
    if (columnDefinitionName.equals("transaction_type")) {
        return boundStatement.getString(1);
    } else {
        return currTransactionType.get();
    }
}
 
Example #13
Source File: DatastaxBinder.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
public BoundStatementMapper<T> mapTo(ColumnDefinitions variables) {
    MapperKey<DatastaxColumnKey> mapperKey = DatastaxColumnKey.mapperKey(variables);
    BoundStatementMapper<T> mapper = cache.get(mapperKey);

    if (mapper == null) {
        mapper = createMapper(mapperKey);
    }
    return mapper;
}
 
Example #14
Source File: DatastaxColumnKey.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
public static MapperKey<DatastaxColumnKey> mapperKey(ColumnDefinitions metaData) {
	DatastaxColumnKey[] keys = new DatastaxColumnKey[metaData.size()];

	for(int i = 0; i < metaData.size(); i++) {
		keys[i] = of(metaData, i);
	}

	return new MapperKey<DatastaxColumnKey>(keys);
}
 
Example #15
Source File: DoubleSession.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private ResultSet mockResultSet(List<Row> rows,ColumnDefinitions columDefiniton){
    ResultSet resultSet = mock(ResultSet.class);
    ColumnDefinitions.Definition mockDefinition = new DoubleDefinition().buildDefinitionWithName("");
    expect(resultSet.getColumnDefinitions()).andStubReturn(columDefiniton);
    expect(resultSet.all()).andStubReturn(rows);
    replay(resultSet);
    return resultSet;
}
 
Example #16
Source File: CQL2CSV.java    From cqlkit with Apache License 2.0 5 votes vote down vote up
@Override
protected void head(ColumnDefinitions columnDefinitions, PrintStream out) {
    definitions = columnDefinitions.asList().toArray(new ColumnDefinitions.Definition[]{});
    csvFormat = CSVFormat.DEFAULT;

    // Print the header
    if (!commandLine.hasOption("H")) {
        List<String> list = columnDefinitions.asList().stream()
                .map(col -> col.getName())
                .collect(Collectors.toList());
        if (commandLine.hasOption("l")) {
            list.add(0, "linenumber");
        }
        if (commandLine.hasOption("queryKeys")) {
            list.add("tokenPercentage");
        }

        try {
            CSVPrinter print = csvFormat
                    .withHeader(list.toArray(new String[]{}))
                    .print(out);
            print.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example #17
Source File: CQL2JSON.java    From cqlkit with Apache License 2.0 5 votes vote down vote up
@Override
protected void head(ColumnDefinitions columnDefinitions, PrintStream out) {
    definitions = columnDefinitions.asList().toArray(new ColumnDefinitions.Definition[]{});

    // Json Columns
    if (commandLine.hasOption("j")) {
        String cols = commandLine.getOptionValue("j");
        String[] arCols = cols.split(",");
        jsonColumns.addAll(Arrays.asList(arCols));
    }
}
 
Example #18
Source File: CassandraSessionImplTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
private static PreparedStatement mockPreparedStatement() {
    PreparedStatement ps = mock(PreparedStatement.class);
    when(ps.getVariables()).thenReturn(mock(ColumnDefinitions.class));
    when(ps.getPreparedId()).thenReturn(mock(PreparedId.class));
    when(ps.getQueryString()).thenReturn("insert into xxx");
    return ps;
}
 
Example #19
Source File: DoubleSession.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private ColumnDefinitions mockColumnDefinions(){
    ColumnDefinitions columnDefinions = mock(ColumnDefinitions.class);
    List<ColumnDefinitions.Definition> columnDefinitions = new ArrayList<>();
    columnDefinitions.add(new DoubleDefinition().buildDefinitionWithName(""));
    expect(columnDefinions.asList()).andStubReturn(columnDefinitions);
    replay(columnDefinions);
    return columnDefinions;
}
 
Example #20
Source File: DoubleSession.java    From Explorer with Apache License 2.0 5 votes vote down vote up
private ColumnDefinitions mockColumnDefinionsWithoutData(){
    ColumnDefinitions columnDefinions = mock(ColumnDefinitions.class);
    List<ColumnDefinitions.Definition> columnDefinitions = new ArrayList<>();
    expect(columnDefinions.asList()).andStubReturn(columnDefinitions);
    replay(columnDefinions);
    return columnDefinions;
}
 
Example #21
Source File: CassandraPOJOOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
private void populateFieldInfosFromPojo(ColumnDefinitions rsMetaData)
{
  fieldInfos = Lists.newArrayList();
  Field[] fields = pojoClass.getDeclaredFields();
  for (int i = 0; i < rsMetaData.size(); i++) {
    String columnName = rsMetaData.getName(i);
    String pojoField = getMatchingField(fields, columnName);
    if (pojoField != null && pojoField.length() != 0) {
      fieldInfos.add(new FieldInfo(columnName, pojoField, null));
    } else {
      LOG.warn("Couldn't find corrosponding pojo field for column: " + columnName);
    }
  }
}
 
Example #22
Source File: CqlDataDaoImpl.java    From staash with Apache License 2.0 5 votes vote down vote up
private String convertResultSet(ResultSet rs) {
    // TODO Auto-generated method stub
    String colStr = "";
    String rowStr = "";
    JsonObject response = new JsonObject();
    List<Row> rows = rs.all();
    if (!rows.isEmpty() && rows.size() == 1) {
        rowStr = rows.get(0).toString();
    }
    ColumnDefinitions colDefs = rs.getColumnDefinitions();
    colStr = colDefs.toString();
    response.putString("columns", colStr.substring(8, colStr.length() - 1));
    response.putString("values", rowStr.substring(4, rowStr.length() - 1));
    return response.toString();
}
 
Example #23
Source File: QueryUtils.java    From staash with Apache License 2.0 5 votes vote down vote up
public static String formatQueryResult(com.datastax.driver.core.ResultSet rs) {
    // TODO Auto-generated method stub
    String colStr = "";
    String rowStr = "";
    JsonObject response = new JsonObject();
    List<Row> rows = rs.all();
    if (!rows.isEmpty() && rows.size() == 1) {
        rowStr = rows.get(0).toString();
    }
    ColumnDefinitions colDefs = rs.getColumnDefinitions();
    colStr = colDefs.toString();
    response.putString("columns", colStr.substring(8, colStr.length() - 1));
    response.putString("values", rowStr.substring(4, rowStr.length() - 1));
    return response.toString();
}
 
Example #24
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public List<ODataEntry> readTableWithKeys(String tableName, ODataEntry keys) throws ODataServiceFault {
    List<ColumnMetadata> cassandraTableMetaData = this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                              .getTable(tableName).getColumns();
    List<String> pKeys = this.primaryKeys.get(tableName);
    String query = createReadSqlWithKeys(tableName, keys);
    List<Object> values = new ArrayList<>();
    for (String column : this.tableMetaData.get(tableName).keySet()) {
        if (keys.getNames().contains(column) && pKeys.contains(column)) {
            bindParams(column, keys.getValue(column), values, cassandraTableMetaData);
        }
    }
    PreparedStatement statement = this.preparedStatementMap.get(query);
    if (statement == null) {
        statement = this.session.prepare(query);
        this.preparedStatementMap.put(query, statement);
    }
    ResultSet resultSet = this.session.execute(statement.bind(values.toArray()));
    List<ODataEntry> entryList = new ArrayList<>();
    Iterator<Row> iterator = resultSet.iterator();
    ColumnDefinitions definitions = resultSet.getColumnDefinitions();
    while (iterator.hasNext()) {
        ODataEntry dataEntry = createDataEntryFromRow(tableName, iterator.next(), definitions);
        entryList.add(dataEntry);
    }
    return entryList;
}
 
Example #25
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public List<ODataEntry> readTable(String tableName) throws ODataServiceFault {
    Statement statement = new SimpleStatement("Select * from " + this.keyspace + "." + tableName);
    ResultSet resultSet = this.session.execute(statement);
    Iterator<Row> iterator = resultSet.iterator();
    List<ODataEntry> entryList = new ArrayList<>();
    ColumnDefinitions columnDefinitions = resultSet.getColumnDefinitions();
    while (iterator.hasNext()) {
        ODataEntry dataEntry = createDataEntryFromRow(tableName, iterator.next(), columnDefinitions);
        entryList.add(dataEntry);
    }
    return entryList;
}
 
Example #26
Source File: DoubleDefinition.java    From Explorer with Apache License 2.0 4 votes vote down vote up
public  ColumnDefinitions.Definition buildDefinitionWithName(String nameHeader) {
    ColumnDefinitions.Definition definition = mock(ColumnDefinitions.Definition.class);
    return definition;
}
 
Example #27
Source File: QueryCassandra.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Converts a result set into an Avro record and writes it to the given stream.
 *
 * @param rs        The result set to convert
 * @param outStream The stream to which the Avro record will be written
 * @param timeout   The max number of timeUnits to wait for a result set fetch to complete
 * @param timeUnit  The unit of time (SECONDS, e.g.) associated with the timeout amount
 * @return The number of rows from the result set written to the stream
 * @throws IOException          If the Avro record cannot be written
 * @throws InterruptedException If a result set fetch is interrupted
 * @throws TimeoutException     If a result set fetch has taken longer than the specified timeout
 * @throws ExecutionException   If any error occurs during the result set fetch
 */
public static long convertToAvroStream(final ResultSet rs, final OutputStream outStream,
                                       long timeout, TimeUnit timeUnit)
        throws IOException, InterruptedException, TimeoutException, ExecutionException {

    final Schema schema = createSchema(rs);
    final GenericRecord rec = new GenericData.Record(schema);

    final DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(schema);
    try (final DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter)) {
        dataFileWriter.create(schema, outStream);

        final ColumnDefinitions columnDefinitions = rs.getColumnDefinitions();
        long nrOfRows = 0;
        if (columnDefinitions != null) {
            do {

                // Grab the ones we have
                int rowsAvailableWithoutFetching = rs.getAvailableWithoutFetching();
                if (rowsAvailableWithoutFetching == 0) {
                    // Get more
                    if (timeout <= 0 || timeUnit == null) {
                        rs.fetchMoreResults().get();
                    } else {
                        rs.fetchMoreResults().get(timeout, timeUnit);
                    }
                }

                for (Row row : rs) {

                    for (int i = 0; i < columnDefinitions.size(); i++) {
                        final DataType dataType = columnDefinitions.getType(i);

                        if (row.isNull(i)) {
                            rec.put(i, null);
                        } else {
                            rec.put(i, getCassandraObject(row, i, dataType));
                        }
                    }
                    dataFileWriter.append(rec);
                    nrOfRows += 1;

                }
            } while (!rs.isFullyFetched());
        }
        return nrOfRows;
    }
}
 
Example #28
Source File: QueryCassandra.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Avro schema from the given result set. The metadata (column definitions, data types, etc.) is used
 * to determine a schema for Avro.
 *
 * @param rs The result set from which an Avro schema will be created
 * @return An Avro schema corresponding to the given result set's metadata
 * @throws IOException If an error occurs during schema discovery/building
 */
public static Schema createSchema(final ResultSet rs) throws IOException {
    final ColumnDefinitions columnDefinitions = rs.getColumnDefinitions();
    final int nrOfColumns = (columnDefinitions == null ? 0 : columnDefinitions.size());
    String tableName = "NiFi_Cassandra_Query_Record";
    if (nrOfColumns > 0) {
        String tableNameFromMeta = columnDefinitions.getTable(0);
        if (!StringUtils.isBlank(tableNameFromMeta)) {
            tableName = tableNameFromMeta;
        }
    }

    final SchemaBuilder.FieldAssembler<Schema> builder = SchemaBuilder.record(tableName).namespace("any.data").fields();
    if (columnDefinitions != null) {
        for (int i = 0; i < nrOfColumns; i++) {

            DataType dataType = columnDefinitions.getType(i);
            if (dataType == null) {
                throw new IllegalArgumentException("No data type for column[" + i + "] with name " + columnDefinitions.getName(i));
            }

            // Map types from Cassandra to Avro where possible
            if (dataType.isCollection()) {
                List<DataType> typeArguments = dataType.getTypeArguments();
                if (typeArguments == null || typeArguments.size() == 0) {
                    throw new IllegalArgumentException("Column[" + i + "] " + dataType.getName()
                            + " is a collection but no type arguments were specified!");
                }
                // Get the first type argument, to be used for lists and sets
                DataType firstArg = typeArguments.get(0);
                if (dataType.equals(DataType.set(firstArg))
                        || dataType.equals(DataType.list(firstArg))) {
                    builder.name(columnDefinitions.getName(i)).type().unionOf().nullBuilder().endNull().and().array()
                            .items(getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(firstArg))).endUnion().noDefault();
                } else {
                    // Must be an n-arg collection like map
                    DataType secondArg = typeArguments.get(1);
                    if (dataType.equals(DataType.map(firstArg, secondArg))) {
                        builder.name(columnDefinitions.getName(i)).type().unionOf().nullBuilder().endNull().and().map().values(
                                getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(secondArg))).endUnion().noDefault();
                    }
                }
            } else {
                builder.name(columnDefinitions.getName(i))
                        .type(getUnionFieldType(getPrimitiveAvroTypeFromCassandraType(dataType))).noDefault();
            }
        }
    }
    return builder.endRecord();
}
 
Example #29
Source File: CQLOperations.java    From Explorer with Apache License 2.0 4 votes vote down vote up
private List<String> header(ColumnDefinitions definition){
    return new FunctionalList<ColumnDefinitions.Definition,String>(definition.asList()).map(new DefinitionToNameFunction());
}
 
Example #30
Source File: CommonG.java    From bdt with Apache License 2.0 4 votes vote down vote up
/**
 * Checks the different results of a previous query to Cassandra database
 *
 * @param expectedResults A DataTable Object with all data needed for check the results. The DataTable must contains at least 2 columns:
 *                        a) A field column from the result
 *                        b) Occurrences column (Integer type)
 *                        <p>
 *                        Example:
 *                        |latitude| longitude|place     |occurrences|
 *                        |12.5    |12.7      |Valencia  |1           |
 *                        |2.5     | 2.6      |Stratio   |0           |
 *                        |12.5    |13.7      |Sevilla   |1           |
 *                        IMPORTANT: All columns must exist
 * @throws Exception exception
 */
public void resultsMustBeCassandra(DataTable expectedResults) throws Exception {
    if (getCassandraResults() != null) {
        //Map for query results
        ColumnDefinitions columns = getCassandraResults().getColumnDefinitions();
        List<Row> rows = getCassandraResults().all();

        List<Map<String, Object>> resultsListObtained = new ArrayList<Map<String, Object>>();
        Map<String, Object> results;

        for (int i = 0; i < rows.size(); i++) {
            results = new HashMap<String, Object>();
            for (int e = 0; e < columns.size(); e++) {
                results.put(columns.getName(e), rows.get(i).getObject(e));

            }
            resultsListObtained.add(results);

        }
        getLogger().debug("Results: " + resultsListObtained.toString());
        //Map for cucumber expected results
        List<Map<String, Object>> resultsListExpected = new ArrayList<Map<String, Object>>();
        Map<String, Object> resultsCucumber;

        for (int e = 1; e < expectedResults.cells().size(); e++) {
            resultsCucumber = new HashMap<String, Object>();

            for (int i = 0; i < expectedResults.cells().get(0).size(); i++) {
                resultsCucumber.put(expectedResults.cells().get(0).get(i), expectedResults.cells().get(e).get(i));

            }
            resultsListExpected.add(resultsCucumber);
        }
        getLogger().debug("Expected Results: " + resultsListExpected.toString());

        //Comparisons
        int occurrencesObtained = 0;
        int iterations = 0;
        int occurrencesExpected = 0;
        String nextKey;
        for (int e = 0; e < resultsListExpected.size(); e++) {
            iterations = 0;
            occurrencesObtained = 0;
            occurrencesExpected = Integer.parseInt(resultsListExpected.get(e).get("occurrences").toString());

            for (int i = 0; i < resultsListObtained.size(); i++) {

                Iterator<String> it = resultsListExpected.get(0).keySet().iterator();

                while (it.hasNext()) {
                    nextKey = it.next();
                    if (!nextKey.equals("occurrences")) {
                        if (resultsListObtained.get(i).get(nextKey).toString().equals(resultsListExpected.get(e).get(nextKey).toString())) {
                            iterations++;
                        }

                    }

                    if (iterations == resultsListExpected.get(0).keySet().size() - 1) {
                        occurrencesObtained++;
                        iterations = 0;
                    }
                }

                iterations = 0;
            }
            assertThat(occurrencesExpected).overridingErrorMessage("In row " + e + " have been found "
                    + occurrencesObtained + " results and " + occurrencesExpected + " were expected").isEqualTo(occurrencesObtained);

        }
    } else {
        throw new Exception("You must execute a query before trying to get results");
    }
}