How to order by a varchar column numerically in vertica database? - varchar

How to order by a varchar column numerically in vertica database?
For example we can add a +0 in the order by clause in oracle to sort a varchar column numerically.
Thanks!

Use cast as in
select x from foo order by cast(x as int);
You will get an error if not all values can be casted to an int.

I haven't done this before in Vertica, but my advice is the same for this type of problem. Try to figure out how PostgreSQL does it and try that since Vertica is utilizing a lot of PostgreSQL funcitonality.
I just did a quick search and came up with this as a possible solution: http://archives.postgresql.org/pgsql-general/2002-01/msg01057.php
A more thorough search may get you better answers.

If the data is truly numeric data, the '+0' will do conversion as you have requested but if there are any values that can not be converted the query will return an error like the following one:
ERROR: Could not convert "200 ... something" from column table_name.column_name to a number

Related

Pandas executemany nulling out columns

I am using the pandas executemany function to load data into a DB2 database. I am having the following issue: If I insert one record with no NULLs, everything works fine; if I enter multiple records, but one has NULLs in some of the fields, it messes up all the records being inserted. The below illustrates what happens:
Edit: Some additional research, it appears the problem for one of these fields is that Pandas can't handle null integers very well. It looks like I am getting some sort of overflow when it tries to cast a null float to int; when I do explicit cast I get these same values. Is there any way to use the executemany function with null integers?
Edit2: I've tried playing around with the Int64 extension as some answers reference, but still had no luck since it still puts the type as float:

How can i update the column to a particular value in a cassandra table?

Hi I am having a cassandra table. my table has around 200 records in it . later i have altered the table to add a new column named budget which is of type boolean . I want to set the default value to be true for that column . what should be the cql looks like.
I am trying the following command but it didnt work
cqlsh:Openmind> update mep_primecastaccount set budget = true ;
SyntaxException: line 1:46 mismatched input ';' expecting K_WHERE
appreciate any help
thank you
Any operation that would require a cluster wide read before write is not supported (as it wont work in the scale that Cassandra is designed for). You must provide a partition and clustering key for an update statement. If theres only 200 records a quick python script or can do this for you. Do a SELECT * FROM mep_primecastaccount and iterate through ResultSet. For each row issue an update. If you have a lot more records you might wanna use spark or hadoop but for a small table like that a quick script can do it.
Chris's answer is correct - there is no efficient or reliable way to modify a column value for each and every row in the database. But for a 200-row table that doesn't change in parallel, it's actually very easy to do.
But there's another way that can work also on a table of billions of rows:
You can handle the notion of a "default value" in your client code. Pre-existing codes will not have a value for "budget" at all: It won't be neither true, nor false, but rather it will be outright missing (a.k.a. "null"). You client code may, when it reads a row with a missing "budget" value, replace it by some default value of its choice - e.g., "true".

Split data in Amazon Athena / Presto by varchar column

I want to split data in Amazon Athena database by varchar column on similar parts. If I could convert varchar to integer I would use just
some_hash_function(data) mod n. But Athena's hash functions return varbinary and it can't be cast to integer.
So, is it possible to solve this problem in another way?
You can convert an 8 byte varbinary into a bigint using the from_big_endian_64 function. Here is a full example:
select from_big_endian_64(substr(sha256(to_utf8('test')), 1, 8));
Generally, Dain answer is correct, but there is a slight remark: since substr takes varchar as a first argument, but sha256 returns varbinary that code will fail.
Here is a working alternative:
from_big_endian_64(xxhash64(to_utf8(user_id)))

Dynamic Query Item Used for Sorting

I'm using Cognos Framework Manager and I'm creating a Data Item for a dynamic sort. I'm creating the Data Item using a CASE WHEN, here's my sample code:
CASE #prompt('SortOrder', 'string')#
WHEN 'Date' THEN <Date Column>
WHEN 'ID' THEN <String Column>
END
I'm getting this error QE-DEF-0405 Incompatible data types in case statement. Although I can cast the date column into a string wouldn't that make sort go wrong for the 'date' option? Should I cast the date column in a different way, cast the whole case, or am I barking at the wrong tree? In line with my question, should there be a general rule when creating dynamic columns via CASE with multiple column data types?
Column in Framework Manager should have datatype. Only one datatype.
So you need to cast your date column to correctly sortable string.
E.g. 'yyyy-mm-dd' format.
You are using the two different types of data format, so in prompt function use token instead of string (#prompt('sortorder','token')#)

Cassandra CQL: How to select encoded value from column

I have inserted string and integer values into dynamic columns in a Cassandra Column Family. When I query for the values in CQL they are displayed as hex encoded bits.
Can I somehow tell the query to decode the value into a string or integer?
I also would be happy to do this in the CLI if that's easier. There I see you can specify assume <column_family> validator as <type>;, but that applies to all columns and they have different types, so I have to run the assumption and query many times.
(Note that the columns are dynamic, so I haven't specified the validator when creating the column family).
You can use ASSUME in cqlsh like in cassandra-cli (although it only applies to printing values, not sending them, but that ought to be ok for you). You can also use it on a per-column basis, like:
ASSUME <column_family> ('anchor:cnnsi.com') VALUES ARE text;
..although (a), I just tested it, and this functionality is broken in cassandra-1.1.1 and later. I posted a fix at CASSANDRA-4352. And (b), this probably isn't a very versatile or helpful solution for more than a few one-off uses. I'd strongly recommend using CQL 3 here, as CQL direct support for wide storage engine rows like this is deprecated. Your table here is certainly adaptable to an (easier to use) CQL 3 model, but I couldn't say exactly what it would be without knowing more about how you're using it.

Resources