I am building a model that allows users to configure a table in mongodb and increment values based on row, column name. Below is my model:
public Class Matrix{
String id;
List<String> columns;
List<String> rows;
long[][] values;
}
When a new object is saved, I populate the Matrix with all 0's,
object.setValues(new long[object.getRows().size()][object.getColumns().size()]);
My use case is, I need to increment the corresponding number when a word for row and column is encountered. Labels for columns and rows are stored in corresponding lists. So, I am trying to do something like this:
matrix.update(<get the index of both row and column value and update values[][] accordingly>)
However, I can't seem to find/form a query that will do both (i.e. return index and update the value). Another approach would be to get the document by id and increment it in Java, but that would need two db calls.
Is there any alternate way to do this? Should I change my model?
Related
I want to iterate a dataframe by partitions and for each partition iterate all of its rows and create a deleteList of them that will contain HBase's delete objects for each row.
I'm using Spark and HBase with Java and I've created a Row object with the following code:
df.foreachPartition((ForeachPartitionFunction<Row> iterator -> {
while (iterator.hasNext()) {
Row row = RowFactory.create(iterator.next());
deleteList.add(new Delete(Bytes.toBytes(String.valueOf(row))));
}
}
But it won't work because I cannot access row's value correctly. While df has one column named "hbase_key".
It's hard to tell from your post which class exactly is Row, but I suspect it is org.apache.spark.sql.Row ?
If that's the case, try the methods like getString(i) or similar, where i is the index of the column in the row you are trying to access.
Again, depending on how you are configuring your Hbase access, I suspect that in your case the 0 index would be the value of the row-key of the physical HBase table, and the subsequent indices will be the respective column values that are returned with your row. But again, that would depend on how exactly you arrived at this point in your code.
Your Row object should have methods to access other data types as well, such as getInt(i), etc.
Sorry if this is a newbie question.
If I've a table in my database called Settings with mostly columns of type long and I'm returning the last row in the table to a variable called results with this statement:
List results = em.createQuery("SELECT s FROM Settings s ORDER BY s.idsettings DESC").setMaxResults(1).getResultList();
It gives me an array of type Vector with each index holding a Settings array. How do I get access to the data in the Settings array? http://i.imgur.com/G8AxKKU.png
I need to get the column data and store them as longs in my java program so I can work with them.
It gives me an array of type Vector with each index holding a Settings array
No, as shown in your debugger, it returns a Vector that only contains one element (the one you want).
Just retrieve that object and use getters to read its columns.
Settings settings = (Settings)results.get(0);
long batLow = settings.getBatLow();
long batUp = settings.getBatUp();
...
I have an ArrayList containing multiple elements, each element contains the next fields:
Name
Address
Age
I have a JTable to show the information contained in the ArrayList.
I have a TableRowSorter to filter the information, according to a certain field.
Let´s say after filtering I get only one element, therefore the JTable has now one row. How can I get the index of that element in the original ArrayList? Do I have to implement one more field kind of "ID"?
int viewIndex = 0; // the index in the table of the unique filtered row.
int modelIndex = table.convertRowIndexToModel();
modelIndex is the index of the row in the list backing the table model.
I am working with a program that i have a record for every user. My users have a property with key, PhoneNumber , and its value is an array of strings, [454457,897356]. For example if i wanted to use cypher query:
Start n=node(1)
Return n
It returns 1 record for my node(one row) that the value of column PhoneNumber is an array.
But i want to have record numbers according to the number of values in my array, means that for my example, the query returns 2 records(2 rows) and all of its attributes be the same but in the PhoneNumber column one of them has the value 454457 and the other has the value 897356. Is any way to do that? do i change my cypher query or make some changes in my java code?
Thanks.
There is no way to do that yet, within Cypher. I've submitted a request for it, though:
https://github.com/neo4j/neo4j/issues/30
Here's the thing: a sortable JTable backed by JTableModel with an array of objects that populate rows (one object = one row). Need to delete rows.
Without sorting, deleting an object is simple: get selected row index, delete array object under the same index. With sorting, though, row indexes mess up in a sense that they no longer match backing array object indexes. What's the proper way to overcome this?
Oscar was almost right, here's how it should be done:
int selectedRow = table.getSelectedRow();
tableModel.removeRow(table.convertRowIndexToModel(selectedRow));
I think ( not quite sure ) there is a method like "modelToView" which returns the actual index in the model a view index represents.
So, for instance you have A,B,C,D and then you sort desc. D,C,B,A this method would return 0 for view index 3 ( A )
I think this was on JXTable which supports sorting or in JTable in Java 6.
If you have build this sorting your self, consider adding this method.