I'm new in cassandra and hector.
I want to retrieve all columns of a row in Cassandra using hector.
After some exploration on web i got some sample codes, but it requires range or column name, like,
SliceQuery<String,String,String> query = HFactory.createSliceQuery(keyspace, ss, ss, ss);
query.setColumnFamily("MyColumnFamily").setKey("S001").setRange(null, null, false, 100);
QueryResult<ColumnSlice<String,String>> result = query.execute();
for (HColumn<String, String> column : result.get().getColumns()) {
System.out.println(column.getName() +"::"+ column.getValue());
}
Here i need to set Range in setRange() method which retrieves columns in this range. We can also set start and end in this method, but this will also give columns of particular range. If i'm not setting range then I need to give Column names as array.
Is there any way to get all columns of particular row?
I don't want to set range or column names, I just want all columns of a row. because in my application columns are not predefined.
Or is there any way to get total column count of a row so i can set it in setRange() method?
Thanks.
The way to do this for somewhat small rows is using the setRange() method exactly how it is being used in the example you pasted. If you set the start and end parameters of the range to null, then the range to fetch from is the entire row.
The only thing you need to account for at that point is the limit. In the example you pasted the limit is set to 100, so the query will not return more than 100 columns. You can set the limit to a very large number (larger than the possible number of columns you would have) if you want to always retrieve all of the columns in a row but this is not generally a good idea.
Instead you probably want to create a hector ColumnSliceIterator, for the range query, which will give you an iterator interface for the row and allow you to iterate through the entire row without querying for too many columns at once. See the example under 'Column Iteration' at the bottom of this page:
https://github.com/rantav/hector/wiki/Getting-started-%285-minutes%29
Related
I'm still learning VBA. I'm having a requirement in which I need to work on rows which are not empty in a particular column. I tried For loop. But considering 10 thousand entries in the Excel, there were performance issues. Can you suggest a while loop which only jumps to the rows which has value and not through all the rows?
Basically I need the handle of all the rows which are not empty.
SpecialCells is your friend here.
If you want all Cells that have Constant Values in them from Column A, then you can use Columns(1).SpecialCells(xlCellTypeConstants)
If you want all Cells that have a Formula in them from Column A, then you can use Columns(1).SpecialCells(xlCellTypeFormulas)
If you want all Cells that are Blank from Column A, then you can use Columns(1).SpecialCells(xlCellTypeBlanks)
Together, these 3 will give you all cells in the column. This means that "Non Blank" will be xlCellTypeConstants combined with xlCellTypeFormulas. Another name for "combination" is Union, which lets us stick Ranges together
Dim rngNonBlank AS Range
Set rngNonBlank = Union(Columns(1).SpecialCells(xlCellTypeConstants), _
Columns(1).SpecialCells(xlCellTypeFormulas))
Dim rngLoopThrough AS Range
For Each rngLoopThrough In rngNonBlank
'You can use rngLoopThrough.EntireRow to get the entire Row
Next rngLoopThrough
I'm trying to develop an Excel application that asks our 4D database for information. To do that, I built a query builder and it works. Now I want to make it more generic so that when I call the query builder, I can pass it a range in which the tables and fields the query is based on are stored. Here is a line where I call the sub and pass it the parameters:
QueryDatabase Worksheets("TablesAndFields").Range("A2:R20"), Worksheets("TablesAndFields"), Worksheets("Import")
Here is the first line in the sub:
Sub QueryDatabase(QuerySpecs As Range, QuerySheet As Worksheet, TargetSheet As Worksheet)
One of the things I need to do is have the VBA figure out the row of the last fields in the various columns. Here is my current code:
LastRowReportTables = QuerySpecs.Offset(0, 3).End(xlDown).Row
LastRowQuery = QuerySpecs.Offset(0, 6).End(xlDown).Row
LastRowSort = QuerySpecs.Offset(0, 14).End(xlDown).Row
This returns the same value for all 3 of them (the second line of the range). It seems to do this regardless of which cells have values in them. For instance, in the case of the range specified above it will return 3. If the range is "A22:R40" it returns 23. What I really need is for it to return the row relative to it's position in the range, but I could fake that if necessary by subtracting the largest multiple of 20 less than the result. (I'm formatting my query builder to fit in 19 rows + a buffer row.) So far, I haven't even been able to get it to return different results for the LastRow variables.
In addition to the Offset method you see above, I've also tried putting it in a With QuerySpecs... End With block. I don't remember the exact result, but I couldn't get that to work either.
The next thing I will need to do is pull values out of the various cells kind of like this:
strStartCell = QuerySpecs.Offset(0, 18).Value
This throws a Run time error 13: Type mismatch. Does anybody have any advice on how to accomplish my goals? Thank-you!
I suggest reading the documentation of the resources you are trying to use.
This can be done by selecting the word which you want to search in the documentation, then press the [F1] key, that will take you to the Microsoft documentation page (i.e. if you select Row and press [F1] will take you to the page Range.Row Property (Excel).
Reading the documentation for Row and Offset will help you understand these Range.Properties and the returns you are getting from your code.
To get the last non-empty row in a range of one column, assuming all data in the range is continuous (i.e. there are no empty cells between rows with content), use these lines:
With WorksheetFunction
LastRowReportTables = .CountA(QuerySpecs.Columns(4))
LastRowQuery = .CountA(QuerySpecs.Columns(7))
LastRowSort = .CountA(QuerySpecs.Columns(15))
End With
Note: If the "QuerySpecs" range is a kind of database, all columns in the fields should have the same number of records, if so, it should be sufficient to obtain the last row for one field only.
To obtain the value of a cell within a range, use this line:
This returns the value of the field (column) 18,row 13 of the QuerySpecs range
strStartCell = QuerySpecs.Cells(13, 18).Value2
The Run-time error 13: Type mismatch is generated when trying to assign an array to a string variable.
Here's a quick summary of what I am trying to do:
I'm trying to set up an Excel workbook that will allow users to paste the results of a SQL query into a RawData worksheet and have multiple other worksheets then grab that data and display it in various formats (graphs, charts, etc.).
This particular formula that I'm trying to write is supposed to look at a certain column in RawData, compare the number listed there to a "key" in the Key worksheet, and then return the text equivalent to the ID displayed in RawData in a new worksheet called StylizedData
For example, if RawData lists 1, then StylizedData will list "Configuration" because 1 is associated with "Configuration" in the Key.
Here is the formula:
=IF(RawData!F60=Key!$C$2,Key!$D$2,
IF(RawData!F60=Key!$C$3,Key!$D$3,
IF(RawData!F60=Key!$C$4,Key!$D$4,
IF(RawData!F60=Key!$C$5,Key!$D$5,
IF(RawData!F60=Key!$C$6,Key!$D$6,
IF(RawData!F60=Key!$C$7,Key!$D$7,
IF(RawData!F60=Key!$C$8,Key!$D$8,
IF(RawData!F60=Key!$C$9,Key!$D$9,
IF(RawData!F60=Key!$C$10,Key!$D$10,
IF(RawData!F60=Key!$C$11,Key!$D$11,
IF(RawData!F60=Key!$C$12,Key!$D$12,
IF(RawData!F60=Key!$C$13,Key!$D$13,
IF(RawData!F60=Key!$C$14,Key!$D$14,
IF(RawData!F60=Key!$C$15,Key!$D$15,
IF(RawData!F60=Key!$C$16,Key!$D$16,
IF(RawData!F60=Key!$C$17,Key!$D$17,
IF(RawData!F60=Key!$C$18,Key!$D$18,
IF(RawData!F60=Key!$C$19,Key!$D$19,
IF(RawData!F60=Key!$C$20,Key!$D$20,
IF(RawData!F60="",""))))))))))))))))))))
That whole process is working correctly all the way up until I get to the point where a row in RawData is empty. When the row is empty, it is displaying "No Subcategory", which is the text equivalent of Key!$C$2 and is contained in Key!$D$2. I'm wanting it to display nothing, which I'm trying to accomplish with that last snippet (IF(RawData!F60="","")).
Can anyone help me out here?
Thanks in advance.
Try,
=iferror(vlookup(RawData!F60, Key!$C$2:$D$20, 2, false), text(,))
=if(iserror(vlookup(RawData!F60,KeyArray,2,0)),"",vlookup(RawData!F60,KeyArray,2,0)
If the lookup value isn't found the cell gets a "" value. Otherwise it will search for the value contained in F60 in your key array and return the value two cells to the right.
With Vlookup() your array/range must have the values you are searching for in the first column. Your column/array must also include the column of values you want to return. For instance you would probably use something like $C$2:$D$20 for your key array. It also helps if your key values in your key array are sorted.
Good luck!
I'd like to reference a single cell in a table, from outside the table, using square-bracket sheet-formula notation.
Something like:
[MyTable[MyField] 3]
or
[MyTable[MyField] 3:3]
-to reference the 3rd row of the MyField column, or:
[MyTable[MyField] MyRow]
-to reference the MyRow row (leftmost row-header) of the MyField column.
Needs to work from outside the table, ie can't use # or #ThisRow.
Not looking for methods involving MATCH, INDEX, OFFSET, etc. Not looking for VBA methods. Just straightforward table-notation. Not looking for manually creating named ranges.
Why? Because, Tables :)
Pre-2013 Excel.
(PS, didn't there used to be a way (pre-Tables) to reference cells by row and column headers? I think it was maybe called "auto-naming", or something like that.)
heh, well this works:
=Table1[Column2] 3:3
So that's progress :)
Just awesome would be a way to reference a row by the contents of left-most column.
Thx!
You can also use index() function as in:
index(MyTable[MyField], 3)
So you get row 3 from the column MyField in table MyTable.
Reference:
https://www.ozgrid.com/forum/forum/help-forums/excel-general/116365-reference-a-single-cell-in-a-table-using-structured-referencing
We can reuse the idea of the intersection operator (i.e. a space between two references) and improve it to have the relative row number of the targeted item in the table, referred to as row_nb here:
=tbl[col] OFFSET(tbl[[#Headers],[col]],row_nb,)
or just without intersection actually (cf. comment below):
=OFFSET(tbl[[#Headers],[col]],row_nb,)
E.g. =Table1[Column2] OFFSET(Table1[[#Headers],[Column2]],2,)
This way you do not depend on the position of the table in the worksheet. Well, it yields a more complicated formula where table name tbl and column name col appear twice. Here are some comments about it:
You can of course keep the OFFSET(...) part only. The downside is that the formula will never return any error if row_nb exceeds the actual number of line items in the table. It'll return e.g. just 0 if the cells below the table are empty.
Keeping a formula that throws an error when we refer to an off-table row, we can further improve it: make it "dynamic" by letting tbl, col and row_nb be parameters:
=INDIRECT(tbl&"["&col&"]") OFFSET(INDIRECT(tbl&"[[#Headers],["&col&"]]"),row_nb,)
Assuming that we've defined tbl, col and row_nb as named ranges. Or else just use cell addresses:
=INDIRECT(A1&"["&A2&"]") OFFSET(INDIRECT(A1&"[[#Headers],["&A2&"]]"),A3,)
I'm not a big fan of INDIRECT but in this case it really comes in handy to let the formula adapt to various tables, columns and line items.
To handle tables that don't start at the first row of a worksheet, we can use the ROW() function. We can determine the first row of the data in the table with:
=ROW(myTable)
Using this and the Indirect() Function we can identify the first cell in a named column with
= myTable[myField] INDIRECT(ROW(myTable) & ":" & ROW(myTable))
The 3rd cell in that column would be:
= myTable[myField] INDIRECT(ROW(myTable)+3 & ":" & ROW(myTable)+3)
I'm using cfspreadsheet to generate an Excel spreadsheet using ColdFusion. I insert a header row, and then use spreadsheetAddRows to dump a query into the sheet. The problem is that the columns are often not wide enough. I know I can use SpreadsheetSetColumnWidth to adjust each column individually, but is there any way that I can just apply an auto-width to the entire sheet? I don't know the max width of each column, and I don't want to apply it to each column individually. Excel has an auto-width feature for columns — is there any way to trigger it from the ColdFusion code? (Or even better: Can I add on to the auto-width — set each column to the max width + 2 or something?)
Last I checked there was not a documented CF function. However you can use POI's autoSizeColumn(columnIndex) method to auto size each column. Just note POI uses base zero for sheet and column indexes.
<cfscript>
// create a workbook and add a long value
wb = SpreadSheetNew();
spreadSheetSetCellValue(wb, repeatString("x", 200), 1, 1);
// get the first sheet
sheet = wb.getWorkBook().getSheetAt( javacast("int", 0) );
// resize first column ie "A"
sheet.autoSizeColumn( javacast("int", 0) );
spreadSheetWrite( wb, "c:/test.xls", true );
</cfscript>