コード例 #1
0
        private static void Sink <T> (T x, string hbase_row_key)
        {
            Console.WriteLine("Sink hit count: " + hitCount++);
            ChangeEvent rowevent = (ChangeEvent)(object)x;

            PropertyInfo[] props = rowevent.GetType().GetProperties();

            List <RequestManager.CellElement> cells = new List <RequestManager.CellElement>();
            string key = "";

            foreach (PropertyInfo pi in props)
            {
                //skip the PrimaryKey which acts as key in HBase
                if (pi.Name == hbase_row_key)
                {
                    //Console.WriteLine("key: " + pi.GetValue(rowevent, null).ToString());
                    key = RequestManager.ToBase64(pi.GetValue(rowevent, null).ToString());
                    continue;
                }

                // if have Byte[], need to convert to string
                if (pi.PropertyType == typeof(Byte[]))
                {
                    string byteCol = RequestManager.ToBase64("cf:" + pi.Name);
                    string byteVal = RequestManager.ToBase64(pi.GetValue(rowevent, null) == null ? "NULL" : BitConverter.ToString((Byte[])pi.GetValue(rowevent, null)));
                    RequestManager.CellElement byteCell = new RequestManager.CellElement {
                        column = byteCol, value = byteVal
                    };
                    cells.Add(byteCell);
                    continue;
                }

                //set up cellelement with column and value
                string col = RequestManager.ToBase64("cf:" + pi.Name);
                string val = pi.GetValue(rowevent, null) == null ? "NULL" : pi.GetValue(rowevent, null).ToString();

                //Console.WriteLine("col: " + pi.Name);
                //Console.WriteLine("val: " + val);

                val = RequestManager.ToBase64(val);

                RequestManager.CellElement cell = new RequestManager.CellElement {
                    column = col, value = val
                };
                cells.Add(cell);
            }
            ;

            RequestManager.RowElement row = new RequestManager.RowElement()
            {
                key = key, Cell = cells
            };
            requestHolder.addRow(row);
        }
コード例 #2
0
        private static void Sink <SourceEvent>(SourceEvent x, string HBASE_ROW_KEY)
        {
            SourceEvent rowevent = x;

            PropertyInfo[] props = rowevent.GetType().GetProperties();

            List <RequestManager.CellElement> cells = new List <RequestManager.CellElement>();
            string key = "";

            foreach (PropertyInfo pi in props)
            {
                //skip the PrimaryKey which acts as key in HBase
                if (pi.Name == HBASE_ROW_KEY)
                {
                    key = RequestManager.ToBase64(pi.GetValue(rowevent, null).ToString());
                    continue;
                }

                // if have Byte[], need to convert to string
                if (pi.PropertyType == typeof(Byte[]))
                {
                    string byteCol = RequestManager.ToBase64("cf:" + pi.Name);
                    string byteVal = RequestManager.ToBase64(pi.GetValue(rowevent, null) == null ? "NULL" : BitConverter.ToString((Byte[])pi.GetValue(rowevent, null)));
                    RequestManager.CellElement byteCell = new RequestManager.CellElement {
                        column = byteCol, value = byteVal
                    };
                    cells.Add(byteCell);
                    continue;
                }

                //set up cellelement with column and value
                string col = RequestManager.ToBase64("cf:" + pi.Name);
                string val = RequestManager.ToBase64(pi.GetValue(rowevent, null) == null ? "NULL" : pi.GetValue(rowevent, null).ToString());
                RequestManager.CellElement cell = new RequestManager.CellElement {
                    column = col, value = val
                };
                cells.Add(cell);
            }
            ;

            RequestManager.RowElement row = new RequestManager.RowElement()
            {
                key = key, Cell = cells
            };

            requestHolder.addRow(row);
        }