Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!
Labels (1)
avatar

Sharing source code I wrote to a prospect that wants to try Phoenix + .NET.

It's a simple code that POST the query to Phoenix Server and parse result JSON and prints results on console:

using System;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Text;
 
namespace ConsoleApplication1
{
    class PhoenixSample
    {
    
        public class FirstFrame
        {
            public String offset;
            public List<List<String>> rows;
        }
        public class Result
        {
            public FirstFrame firstFrame;
            public int updateCount;
        }
        public class PhoenixResult
        {
            public string response { get; set; }
            public List<Result> results { get; set; }
        }
 
        static void Main(string[] args)
        {
            try
            {
                string url = "http://192.168.56.203:8765";
                string query = "select * from test";
                var syncClient = new WebClient();
                syncClient.Headers["request"] = "{\"request\":\"prepareAndExecute\",\"connectionId\":\"b27cbc83-a514-49f0-9bbe-f15d8bfb3532\",\"sql\":\"" + query + "\",\"maxRowCount\":-1}";
                syncClient.Headers["Content-Type"] = "application/json";
                byte[] responseArray = syncClient.UploadData(url, "POST", Encoding.ASCII.GetBytes(""));
                string json = Encoding.ASCII.GetString(responseArray);
 
                System.Diagnostics.Debug.WriteLine("teste");
                System.Diagnostics.Debug.WriteLine("json=" + json);
 
                PhoenixResult test = JsonConvert.DeserializeObject<PhoenixResult>(json);
                System.Diagnostics.Debug.WriteLine(test.response);
                System.Diagnostics.Debug.WriteLine(test.results[0].updateCount);
                for (int i = 0; i < test.results[0].firstFrame.rows.Count; i++)
                {
                    for (int j = 0; j < test.results[0].firstFrame.rows[i].Count; j++)
                    {
                        System.Diagnostics.Debug.Write("row # " + i + " col # " + j + " = ");
                        System.Diagnostics.Debug.WriteLine(test.results[0].firstFrame.rows[i][j]);
                    }
                }
 
            }  
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.Read();
            }
 
        }
    }
    }
11,041 Views
Comments
avatar
Guru

Nice! I had made something similar a few months back so this might be my opportunity to share that as well https://github.com/jdye64/PhoenixRESTServer-Client

avatar
New Member

Microsoft released a preview of their .NET ProtoBuf client for Phoenix (hdinsight-phoenix-sharp) on Nuget.org in June 2016. I've found it worked well against my HDP 2.4 (HBASE 1.1.2 / Phoenix 4.4) cluster, but the API was unfamiliar to me. As I learned it, I implemented a System.Data IDbConnection, IDbCommand et al wrapper API around it, named Garuda.Data. It makes access to Phoenix from .NET code feel almost like SqlConnection, SqlCommand, etc - Check it out on Nuget: https://www.nuget.org/packages/Garuda.Data/

Blog post on the topic: http://dwdii.github.io/2016/08/13/Garuda.Data-Apache-Phoenix-For-.NET-Developers.html

Garuda.Data Github Repo: https://github.com/dwdii/GarudaUtil

Version history
Last update:
‎10-26-2015 11:09 PM
Updated by:
Contributors