Example #1
0
        private static string _Get_val_from_usqlarray <T>(USQLINTERFACES.IRow row, USQLINTERFACES.IColumn col, string val)
        {
            var arr = row.Get <USQLTYPES.SqlArray <T> >(col.Name);

            if (arr != null)
            {
                var sb = new System.Text.StringBuilder();
                sb.Append("SqlArray<");
                sb.Append(get_usql_type_name(typeof(T)));
                sb.Append(">{ ");

                for (int j = 0; j < arr.Count; j++)
                {
                    if (j > 0)
                    {
                        sb.Append(", ");
                    }

                    sb.Append("\"");
                    sb.Append(arr[j].ToString());
                    sb.Append("\"");
                }

                sb.Append(" }");
                val = sb.ToString();
            }
            else
            {
                val = "NULL";
            }
            return(val);
        }
Example #2
0
        public static string GetValueFromUsqlMap <K, V>(Microsoft.Analytics.Interfaces.IRow row, Microsoft.Analytics.Interfaces.IColumn col, TypeDisplayNameOptions opts)
        {
            string val = null;

            var map = row.Get <Microsoft.Analytics.Types.Sql.SqlMap <K, V> >(col.Name);

            if (map != null)
            {
                var sb = new System.Text.StringBuilder();
                sb.Append("SqlMap");
                if (opts.ShowGenericParameters)
                {
                    sb.Append(_LESSTHAN);
                    sb.Append(UdoUtils.GetUsqlTypeDisplayName(typeof(K)));
                    sb.Append(_COMMA);
                    sb.Append(_SPACE);
                    sb.Append(UdoUtils.GetUsqlTypeDisplayName(typeof(V)));
                    sb.Append(_GREATERTHAN);
                }
                sb.Append(_LEFTCURLYBRACE);
                sb.Append(_SPACE);

                int kn = 0;
                foreach (var key in map.Keys)
                {
                    if (kn > 0)
                    {
                        sb.Append(_SEMICOLON);
                        sb.Append(_SPACE);
                    }

                    V      xval    = map[key];
                    string val_str = "NULL";
                    if (xval != null)
                    {
                        val_str = xval.ToString();
                    }

                    var key_str = key.ToString();
                    sb.AppendFormat("{0}={1}", key_str, val_str);

                    kn++;
                }
                sb.Append(_SPACE);
                sb.Append(_RIGHTCURLYBRACE);
                val = sb.ToString();
            }
            else
            {
                val = "NULL";
            }
            return(val);
        }
Example #3
0
        private static string _Get_val_from_usqlmap <K, V>(USQLINTERFACES.IRow row, USQLINTERFACES.IColumn col, string val)
        {
            var map = row.Get <USQLTYPES.SqlMap <K, V> >(col.Name);

            if (map != null)
            {
                var sb = new System.Text.StringBuilder();
                sb.Append("SqlMap<");
                sb.Append(get_usql_type_name(typeof(K)));
                sb.Append(", ");
                sb.Append(get_usql_type_name(typeof(V)));
                sb.Append(">{ ");

                int kn = 0;
                foreach (var key in map.Keys)
                {
                    if (kn > 0)
                    {
                        sb.Append("; ");
                    }

                    V      xval    = map[key];
                    string val_str = "NULL";
                    if (xval != null)
                    {
                        val_str = xval.ToString();
                    }

                    var key_str = key.ToString();
                    sb.AppendFormat("{0}={1}", key_str, val_str);

                    kn++;
                }

                sb.Append(" }");
                val = sb.ToString();
            }
            else
            {
                val = "NULL";
            }
            return(val);
        }
Example #4
0
        public static string GetValueFromUsqlArray <T>(Microsoft.Analytics.Interfaces.IRow row, Microsoft.Analytics.Interfaces.IColumn col, string val, TypeDisplayNameOptions opts)
        {
            var arr = row.Get <Microsoft.Analytics.Types.Sql.SqlArray <T> >(col.Name);

            if (arr != null)
            {
                var sb = new System.Text.StringBuilder();
                sb.Append("SqlArray");
                if (opts.ShowGenericParameters)
                {
                    sb.Append(_LESSTHAN);
                    sb.Append(UdoUtils.GetUsqlTypeDisplayName(typeof(T)));
                    sb.Append(_GREATERTHAN);
                }
                sb.Append(_LEFTCURLYBRACE);
                sb.Append(_SPACE);

                for (int j = 0; j < arr.Count; j++)
                {
                    if (j > 0)
                    {
                        sb.Append(_COMMA);
                        sb.Append(_SPACE);
                    }

                    sb.Append(_DOUBLEQUOTE);
                    sb.Append(arr[j].ToString());
                    sb.Append(_DOUBLEQUOTE);
                }

                sb.Append(_SPACE);
                sb.Append(_RIGHTCURLYBRACE);

                val = sb.ToString();
            }
            else
            {
                val = "NULL";
            }
            return(val);
        }
Example #5
0
        private string CreateIndexBody(string indexName, Microsoft.Analytics.Interfaces.IRow row)
        {
            var index = new Index();

            index.fields = new List <Field>();

            index.name = indexName;
            row.Schema.ToList().ForEach((x) =>
                                        index.fields.Add(new Field()
            {
                name       = x.Name,
                type       = x.Type.ToEdmString(),
                key        = (row.Schema.IndexOf(x.Name) == 0 ? true : false),
                searchable = true
            }));

            var settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            string json = JsonConvert.SerializeObject(index, settings);

            return(json);
        }
Example #6
0
        public static string GetValueDisplayString(Microsoft.Analytics.Interfaces.IRow row, Type type, string val, Microsoft.Analytics.Interfaces.IColumn col, TypeDisplayNameOptions opts)
        {
            if (type == typeof(string))
            {
                val = row.Get <string>(col.Name) ?? _NULL;
            }
            else if (type == typeof(bool))
            {
                val = row.Get <bool>(col.Name).ToString();
            }
            else if (type == typeof(char))
            {
                val = row.Get <char>(col.Name).ToString();
            }
            else if (type == typeof(float))
            {
                val = row.Get <float>(col.Name).ToString(System.Globalization.CultureInfo.InvariantCulture);
            }
            else if (type == typeof(double))
            {
                val = row.Get <double>(col.Name).ToString(System.Globalization.CultureInfo.InvariantCulture);
            }
            else if (type == typeof(int))
            {
                val = row.Get <int>(col.Name).ToString();
            }
            else if (type == typeof(long))
            {
                val = row.Get <long>(col.Name).ToString();
            }
            else if (type == typeof(System.Guid))
            {
                val = row.Get <System.Guid>(col.Name).ToString();
            }
            else if (type == typeof(int?))
            {
                val = row.Get <int?>(col.Name).ToString();
            }
            else if (type == typeof(long?))
            {
                val = row.Get <long?>(col.Name).ToString();
            }
            else if (type == typeof(float?))
            {
                val = row.Get <float?>(col.Name).ToString();
            }
            else if (type == typeof(double?))
            {
                val = row.Get <double?>(col.Name).ToString();
            }
            else if (type.IsGenericType)
            {
                val = GetValueFromUsqlArray_(row, type, col, opts);

                if (val == null)
                {
                    val = GetValueFromUsqlMap_(row, type, col, opts);
                }

                if (val == null)
                {
                    val = UdoUtils.GetUsqlTypeDisplayName(type);
                }
            }
            else
            {
                val = UdoUtils.GetUsqlTypeDisplayName(type);
            }
            return(val);
        }
Example #7
0
        public override void Output(USQLINTERFACES.IRow row, USQLINTERFACES.IUnstructuredWriter output)
        {
            var streamWriter = new System.IO.StreamWriter(output.BaseStream);

            // Metadata schema initialization to enumerate column names
            var schema = row.Schema;


            if (this.row_count == 0)
            {
                if (this.OutputHeader)
                {
                    streamWriter.Write("|");
                    for (int i = 0; i < schema.Count(); i++)
                    {
                        var col = schema[i];
                        streamWriter.Write(" ");
                        streamWriter.Write(col.Name);
                        streamWriter.Write(" ");
                        if (this.OutputHeaderType)
                        {
                            streamWriter.Write(get_usql_type_name(col.Type));
                            streamWriter.Write(" ");
                        }
                        streamWriter.Write("|");
                    }
                    streamWriter.Write("\r\n");
                    streamWriter.Flush();

                    streamWriter.Write("|");
                    for (int i = 0; i < schema.Count(); i++)
                    {
                        var col = schema[i];
                        streamWriter.Write(" ");
                        streamWriter.Write("---");
                        streamWriter.Write(" ");
                        streamWriter.Write("|");
                    }
                    streamWriter.Write("\r\n");
                    streamWriter.Flush();
                }
            }

            // Data row output
            streamWriter.Write("|");
            for (int i = 0; i < schema.Count(); i++)
            {
                var    col = schema[i];
                string val = "";

                try
                {
                    var coltype = col.Type;
                    if (coltype == typeof(string))
                    {
                        val = row.Get <string>(col.Name);
                        val = val ?? "NULL";
                    }
                    else if (coltype == typeof(bool))
                    {
                        val = row.Get <bool>(col.Name).ToString();
                    }
                    else if (coltype == typeof(char))
                    {
                        val = row.Get <char>(col.Name).ToString();
                    }
                    else if (coltype == typeof(float))
                    {
                        val = row.Get <float>(col.Name).ToString();
                    }
                    else if (coltype == typeof(double))
                    {
                        val = row.Get <double>(col.Name).ToString();
                    }
                    else if (coltype == typeof(int))
                    {
                        val = row.Get <int>(col.Name).ToString();
                    }
                    else if (coltype == typeof(long))
                    {
                        val = row.Get <long>(col.Name).ToString();
                    }
                    else if (coltype == typeof(System.Guid))
                    {
                        val = row.Get <System.Guid>(col.Name).ToString();
                    }
                    else if (coltype == typeof(int?))
                    {
                        val = row.Get <int?>(col.Name).ToString();
                        val = val ?? "NULL";
                    }
                    else if (coltype == typeof(long?))
                    {
                        val = row.Get <long?>(col.Name).ToString();
                        val = val ?? "NULL";
                    }
                    else if (coltype == typeof(float?))
                    {
                        val = row.Get <float?>(col.Name).ToString();
                        val = val ?? "NULL";
                    }
                    else if (coltype == typeof(double?))
                    {
                        val = row.Get <double?>(col.Name).ToString();
                        val = val ?? "NULL";
                    }
                    else if (coltype == typeof(USQLTYPES.SqlArray <string>))
                    {
                        val = _Get_val_from_usqlarray <string>(row, col, val);
                    }
                    else if (coltype == typeof(USQLTYPES.SqlArray <int>))
                    {
                        val = _Get_val_from_usqlarray <int>(row, col, val);
                    }
                    else if (coltype == typeof(USQLTYPES.SqlArray <long>))
                    {
                        val = _Get_val_from_usqlarray <long>(row, col, val);
                    }
                    else if (coltype == typeof(USQLTYPES.SqlMap <string, string>))
                    {
                        val = _Get_val_from_usqlmap <string, string>(row, col, val);
                    }
                    else if (coltype == typeof(USQLTYPES.SqlMap <string, int?>))
                    {
                        val = _Get_val_from_usqlmap <string, int?>(row, col, val);
                    }
                    else
                    {
                        val = "UNKNOWNTYPE:" + get_usql_type_name(coltype);
                    }
                }
                catch (System.NullReferenceException exc)
                {
                    // Handling NULL values--keeping them empty
                    val = "NullReferenceException";
                }
                streamWriter.Write(" ");
                streamWriter.Write(val);
                streamWriter.Write(" ");
                streamWriter.Write("|");
            }
            streamWriter.Write("\n");
            streamWriter.Flush();

            this.row_count++;
        }
Example #8
0
        public override void Output(USQLINTERFACES.IRow row, USQLINTERFACES.IUnstructuredWriter output)
        {
            var streamWriter = new System.IO.StreamWriter(output.BaseStream);

            // Metadata schema initialization to enumerate column names
            var schema = row.Schema;

            var opts = new TypeDisplayNameOptions();

            if (this.row_count == 0)
            {
                if (this.OutputHeader)
                {
                    streamWriter.Write(this._FieldSeparator);
                    for (int i = 0; i < schema.Count(); i++)
                    {
                        var col = schema[i];
                        streamWriter.Write(this._Space);
                        streamWriter.Write(col.Name);
                        streamWriter.Write(this._Space);
                        if (this.OutputHeaderType)
                        {
                            streamWriter.Write(UdoUtils.GetUsqlTypeDisplayName(col.Type));
                            streamWriter.Write(this._Space);
                        }
                        streamWriter.Write(this._FieldSeparator);
                    }
                    streamWriter.Write(_LineSeparator);
                    streamWriter.Flush();

                    streamWriter.Write(this._FieldSeparator);
                    for (int i = 0; i < schema.Count(); i++)
                    {
                        var col = schema[i];
                        streamWriter.Write(this._Space);
                        streamWriter.Write(this._Header);
                        streamWriter.Write(this._Space);
                        streamWriter.Write(this._FieldSeparator);
                    }
                    streamWriter.Write(_LineSeparator);
                    streamWriter.Flush();
                }
            }

            // Data row output
            streamWriter.Write(this._FieldSeparator);
            for (int i = 0; i < schema.Count(); i++)
            {
                var    col = schema[i];
                string val = string.Empty;

                try
                {
                    var coltype = col.Type;
                    val = UdoUtils.GetValueDisplayString(row, coltype, val, col, opts);
                }
                catch (System.NullReferenceException exc)
                {
                    // Handling NULL values--keeping them empty
                    val = "NullReferenceException";
                }

                streamWriter.Write(this._Space);

                if (this.EncodeHtml)
                {
                    var encoded_val = System.Web.HttpUtility.HtmlEncode(val);
                    val = encoded_val;
                }

                streamWriter.Write(val);
                streamWriter.Write(this._Space);
                streamWriter.Write(this._FieldSeparator);
            }
            streamWriter.Write(this._LineSeparator);
            streamWriter.Flush();

            this.row_count++;
        }