Aerospike - How to convert BinMap to JSON using golang driver - aerospike

The data fetched from database is always of the type:
map[interface{}]interface{}
This type is not supported by json.Marshal() function in go. What is the best way to get JSON from the map?

BinMap is basically a map[string]interface{}. That is not your problem.
Your issue seems to be that you have bins which are maps, and since maps are represented as map[interface{}]interface{} and those are not supported by json.Marshal, you are getting an error.
The easiest workaround is to use github.com/json-iterator/go as a drop-in replacement, which supports marshaling of map[interface{}]interface{}.

Related

what is the difference between FixedLenSequenceFeature and VarLenFeature?

I used to specify VarLenFeature when I want to decode variable-length input feature, but recently I noticed there is a FixedLenSequenceFeature could do the same thing for me, so what's the difference between these two class? and when should I use one instead of the other? I can get nearly nothing from the documentation.
VarLenFeature
FixedLenSequenceFeature

Splitting Nef polyhedra into discrete volumes for conversion to regular polyhedra

I am doing some boolean operation on Nef polyhedra converted from regular polyhedra. After doing the boolean operation I want to convert the resulting Nef polyhedra into regular polyhedra. However it seems that Nef polyhedra only support if the result is a single volume. Some boolean operations however result in multiple volumes. Is there a way to split the Nef polyhedron into into the discrete volumes it contains and convert these back to regular polyhedra separately? Alternatively is there some more appropriate approach?
I have found the Nef_polyhedron_3::Volume and the corresponding iterator, but i have not been able to identify a way to utilize these to split up the Nef Polyhedron.
Edit:
I finally got around to properly look at this. The code provided worked almost out of the box. I ran in to a few issues that were pretty easily solved. First, i implemented BuildPolyhedronFromShell outside the Nef_polyhedron class as i would like to keep my CGAl Implementation as clean as possible. It was however necessary to make Nef_polyhedron_3::Triangulation_handler2 public, as it is used in BuildPolyhedronFromShell.
Additionally the code initially create shells with inward facing normals. This was fixed by changing Halffacet_const_handle f = opposite_facet->twin(); to Halffacet_const_handle f = opposite_facet; I don't know if this solves the problem in the general case, but i works for the cases i tried.
Thank you for the help.

How to write to a file in Go

I have seen How to read/write from/to file using golang? and http://golang.org/pkg/os/#File.Write but could not get answer.
Is there a way, I can directly write an array of float/int to a file. Or do I have to change it to byte/string to write it. Thanks.
You can use the functions in the encoding/binary package for this purpose.
As far as writing an entire array at once goes, there are no functions for this. You will have to iterate the array and write each element individually. Ideally, you should prefix these elements with a single integer, denoting the length of the array.
If you want a higher level solution, you can try the encoding/gob package:
Package gob manages streams of gobs - binary values exchanged between an Encoder (transmitter) and a Decoder (receiver). A typical use is transporting arguments and results of remote procedure calls (RPCs) such as those provided by package "rpc".

How to add intarray extension to PostgreSQL on Heroku

The app I have is using intarray extension of the PostgreSQL.
Unfortunately it doesn't seem to be available according to the docs and the command line:
> echo 'show extwlist.extensions' | heroku pg:psql
extwlist.extensions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
btree_gist,chkpass,cube,dblink,dict_int,dict_xsyn,earthdistance,fuzzystrmatch,hstore,isn,ltree,pg_trgm,pgcrypto,pgrowlocks,pgstattuple,plpgsql,unaccent,uuid-ossp,citext,tablefunc
(1 row)
Also:
> heroku pg:psql
psql (9.1.5, server 9.1.6)
SSL connection
Type "help" for help.
=> CREATE EXTENSION intarray;
WARNING: extension "intarray" is not whitelisted
CREATE EXTENSION
So does it mean I can't use Heroku or there IS a way to add intarray extension (using idx function for example).
Thanks.
The general consensus from the Postgres community I got was that intarray is obsoleted by just using int[] and that it's only kept around for backwards compatibility for very old applications. That's why we haven't added support for it.
So far everyone who asked for it was actually happier with int[] and just hadn't found it. Is there some usecase where you actually want an intarray column instead? We can just turn it on.
intarray has been whitelisted on Heroku since March 2014, so you should be able to enable the extension directly. If you provisioned your database before that you will first need to upgrade your database.
Have to answer my own question just to provide a little bit more details.
The intarray was used for extracting path information from columns containing strings like 123/312/56/9863. That was stored (poorly) as string instead of an array in the first place.
The reason we needed intarray is because we it had the idx function.
What was happening is this:
convert string to an array
find the given number using the idx
return the next number in sequence.
All that was done as a temporary measure. But since heroku couldn't support idx the only way to use it was by adding a custom function.
But instead we converted the queries and data structure to to use ltree and its index function.
Apart from not needing a dependency on idx (but introducing another dependency on ltree), we also improved the performance of the queries by a factor of x200.

What is the proper way to retrieve string key/values from Redis using BookSleeve

I'm new to BookSleeve and it seems that the API has changed even when compared to what is documented in the website.
AS it is noted in the website:
"Note the API may change a little going to 1.0, but is stable enough to drive Stack Exchange.."
So it seems that the documentation is not current anymore.
Anyway, the question is, what is the correct way to retrieve keys that you have previously stored. I am using the 'String' API.
Is the following correct assumming an opened connection?:
var result = redisConnection.Strings.Get(0, "myKey");
byte[] buffer = redisConnection.Wait(result);
string str = System.Text.Encoding.Unicode.GetString(buffer, 0, buffer.Length);
You can simply use connection.Strings.GetString. But if you do use System.Text.Encoding, then use System.Text.Encoding.UTF8. Redis strings are UTF8.