Esempio n. 1
0
 private void SetInputTypeComboBox(Column.ColumnType inputType)
 {
     foreach (ComboBoxItem item in inputTypeComboBox.Items)
     {
         if (item.ColumnType == inputType)
         {
             inputTypeComboBox.SelectedItem = item;
             break;
         }
     }
 }
 public static bool ColumnTypeClrDependant(Column.ColumnType columnType)
 {
     if (columnType == Column.ColumnType.RegEx || columnType == Column.ColumnType.StoredProcedureName || columnType == Column.ColumnType.StoredProcedureParameter || columnType == Column.ColumnType.LogParameter)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 3
0
 private void SetOutputTypeComboBox(Column.ColumnType outputType)
 {
     foreach (ComboBoxItem item in outputTypeComboBox.Items)
     {
         if (item.ColumnType == outputType)
         {
             outputTypeComboBox.SelectedItem = item;
             break;
         }
     }
 }
    public static string GetColumnTypeName(Column.ColumnType columnType)
    {
        if (ConfigHandler.UseTranslation)
        {
            switch (columnType)
            {
            case Column.ColumnType.RegEx:
                return(Translator.GetText("RegEx"));

            case Column.ColumnType.SQL:
                return(Translator.GetText("SQL"));

            case Column.ColumnType.Constant:
                return(Translator.GetText("Constant"));

            case Column.ColumnType.StoredProcedureName:
                return(Translator.GetText("StoredProcedureName"));

            case Column.ColumnType.StoredProcedureParameter:
                return(Translator.GetText("StoredProcedureParameter"));

            case Column.ColumnType.LogParameter:
                return(Translator.GetText("LogParameter"));
            }
        }
        else
        {
            switch (columnType)
            {
            case Column.ColumnType.RegEx:
                return("RegEx");

            case Column.ColumnType.SQL:
                return("SQL");

            case Column.ColumnType.Constant:
                return("Constant");

            case Column.ColumnType.StoredProcedureName:
                return("Stored Procedure Name");

            case Column.ColumnType.StoredProcedureParameter:
                return("Stored Procedure Parameter");

            case Column.ColumnType.LogParameter:
                return("Log Parameter");
            }
        }

        return(null);
    }
    private static string ColumnTypeToString(Column.ColumnType columnType)
    {
        switch (columnType)
        {
        case Column.ColumnType.RegEx:
            return("RegEx");

        case Column.ColumnType.SQL:
            return("SQL");

        case Column.ColumnType.StoredProcedureName:
            return("StoredProcedureName");

        case Column.ColumnType.StoredProcedureParameter:
            return("StoredProcedureParameter");

        case Column.ColumnType.LogParameter:
            return("LogParameter");
        }

        return("Constant");
    }
Esempio n. 6
0
 public ComboBoxItem(string text, Column.ColumnType columnType)
 {
     Text       = text;
     ColumnType = columnType;
 }
Esempio n. 7
0
        }   // end fromClass()

        /// <summary>
        /// Create a KineticaType object from properties of a record class and Kinetica column properties.
        /// It ignores any properties inherited from base classes, and also ignores any member fields of
        /// the class.
        /// </summary>
        /// <param name="recordClass">A class type.</param>
        /// <param name="label">Any label for the type.</param>
        /// <param name="properties">Properties for the columns.</param>
        /// <returns></returns>
        public static KineticaType fromClass(Type recordClass, string label, IDictionary <string, IList <string> > properties = null)
        {
            // Get the fields in order (******skipping properties inherited from base classes******)
            // (fields only from this type, i.e. do not include any inherited fields), and public types only
            System.Reflection.PropertyInfo[] type_properties = recordClass.GetProperties(System.Reflection.BindingFlags.DeclaredOnly |
                                                                                         System.Reflection.BindingFlags.Instance |
                                                                                         System.Reflection.BindingFlags.Public);
            Array.Sort(type_properties, delegate(System.Reflection.PropertyInfo p1, System.Reflection.PropertyInfo p2)
                       { return(p1.MetadataToken.CompareTo(p2.MetadataToken)); });

            // Need to have a list of columns
            List <Column> columns      = new List <Column>();
            List <string> column_names = new List <string>();

            // Per property, check that it is one of: int, long, float, double, string, bytes
            foreach (var property in type_properties)
            {
                string            column_name       = "";
                Column.ColumnType column_type       = Column.ColumnType.DEFAULT;
                IList <string>    column_properties = null;
                bool is_column_nullable             = false;

                // Get the column name
                column_name = property.Name;

                Type prop_type = property.PropertyType;

                // Check if the field is nullable (declared as T? or Nullable<T>)
                if (property.PropertyType.IsGenericType &&
                    (property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)))
                {   // the field is a nullable field
                    is_column_nullable = true;
                    // Change the property type to be the underlying type
                    prop_type = Nullable.GetUnderlyingType(prop_type);
                }

                // Check the column data type (must be one of int, long, float, double, string, and bytes)
                if (prop_type == typeof(System.String))
                {
                    column_type = Column.ColumnType.STRING;
                }
                else if (prop_type == typeof(System.Int32))
                {
                    column_type = Column.ColumnType.INT;
                }
                else if (prop_type == typeof(System.Int64))
                {
                    column_type = Column.ColumnType.LONG;
                }
                else if (prop_type == typeof(float))
                {
                    column_type = Column.ColumnType.FLOAT;
                }
                else if (prop_type == typeof(double))
                {
                    column_type = Column.ColumnType.DOUBLE;
                }
                else if (prop_type == typeof(byte))
                {
                    column_type = Column.ColumnType.BYTES;
                }
                else
                {
                    throw new KineticaException("Unsupported data type for " + prop_type.Name +
                                                ": " + prop_type +
                                                " (must be one of int, long, float, double, string, and byte)");
                }

                // Extract the given column's properties, if any
                if (properties != null)
                {
                    // This column has properties given
                    properties.TryGetValue(column_name, out column_properties);
                }

                // Keep a list of the column names for checking the properties
                column_names.Add(column_name);

                // Create the column
                Column column = new Column(column_name, column_type, column_properties);
                if (is_column_nullable)   // Set the appropriate nullable flag for the column
                {
                    column.setIsNullable(true);
                }

                // Save the column
                columns.Add(column);
            }  // end looping over all members of the class type

            // Check for extraneous properties
            if (properties != null)
            {
                IEnumerable <string> property_keys = properties.Keys;
                var unknown_columns = property_keys.Where(e => !column_names.Contains(e));
                // Check if any property is provided for wrong/non-existing columns
                if (unknown_columns.Any())
                {
                    throw new KineticaException("Properties specified for unknown columns.");
                }
            }

            // Create the kinetica type
            KineticaType kType = new KineticaType(label, columns, properties);

            // Save the class information in the type
            kType.saveSourceType(recordClass);

            return(kType);
        } // end fromClass()
Esempio n. 8
0
        /// <summary>
        /// Create a KineticaType object based on information provided in a dynamic schema.
        /// </summary>
        /// <param name="dynamic_table_schema_string">The dynamic schema string.</param>
        /// <param name="column_headers">List of column names.</param>
        /// <param name="column_types">List of column types.</param>
        /// <returns></returns>
        public static KineticaType fromDynamicSchema(string dynamic_table_schema_string,
                                                     Object[] column_headers, Object[] column_types)
        {
            // Make sure that the lists of column names and types are of the same length
            if (column_headers.Length != column_types.Length)
            {
                throw new KineticaException("List of column names and types are not of the same length.");
            }

            // Parse the schema string so that we can later check if a given column is nullable
            JObject dynamic_schema_json;

            try
            {
                dynamic_schema_json = JObject.Parse(dynamic_table_schema_string);
            }
            catch (Exception ex)
            {
                throw new KineticaException(ex.ToString());
            }

            // Create a delegate for checking if a field/column is nullable
            // ------------------------------------------------------------
            // The first parameter is the column name, the second is the JSON object
            var is_column_nulllable = new Func <string, JObject, bool>((column_name, schema_json) => {
                // Find the appropriate field
                bool found_field = false;
                foreach (var field in schema_json["fields"])
                {
                    if ((string)field["name"] == column_name)
                    {
                        found_field = true; // found it!
                        // Get the type and see if it's a nullable type
                        // (each field is an array of the column type; so need
                        // to extract the type element first)
                        var type_element = field["type"]["items"];
                        if (type_element is JValue)   // not an array, so can't be nullable
                        {
                            return(false);
                        }
                        // If the type is an array and the second value is 'null', then it's a nullable
                        if ((type_element is JArray) && ((string)((JArray)type_element)[1] == "null"))
                        {
                            return(true);
                        }
                        return(false);
                    } // end if
                }     // end foreach
                if (!found_field)
                {
                    throw new KineticaException($"Could not find the field named '{column_name}'");
                }
                return(false); // shouldn't ever get here
            });

            // Create appropriate columns and column properties
            // ------------------------------------------------
            IList <Column> columns = new List <Column>();
            IDictionary <string, IList <string> > column_properties = new Dictionary <string, IList <string> >();

            for (int i = 0; i < column_headers.Length; ++i)
            {
                // Get the column's name
                string column_name = column_headers[i].ToString();

                // Get the column's type in string format, which might be a property and not a primitive type
                // (if so, then we'll have to infer the primitive type and save the property)
                string column_type_string = column_types[i].ToString();

                // Need to create a list for the properties of the column (we'll
                // extract at most one from the column type)
                IList <string> column_property = new List <string>();

                // We need to also infer the primitive type for this column
                Column.ColumnType column_type = Column.ColumnType.DEFAULT;

                // Infer the type and property from the given 'type'
                switch (column_type_string)
                {
                // Primitive type string (and all properties based on it)
                case "string":
                    column_type = Column.ColumnType.STRING;
                    break;

                // All properties allowed for the primitive string type
                case ColumnProperty.CHAR1:
                case ColumnProperty.CHAR2:
                case ColumnProperty.CHAR4:
                case ColumnProperty.CHAR8:
                case ColumnProperty.CHAR16:
                case ColumnProperty.CHAR32:
                case ColumnProperty.CHAR64:
                case ColumnProperty.CHAR128:
                case ColumnProperty.CHAR256:
                case ColumnProperty.DATE:
                case ColumnProperty.DATETIME:
                case ColumnProperty.DECIMAL:
                case ColumnProperty.IPV4:
                case ColumnProperty.TIME:
                    column_type = Column.ColumnType.STRING;
                    column_property.Add(column_type_string);
                    break;

                // Primitive type integer
                case "int":
                    column_type = Column.ColumnType.INT;
                    break;

                // Properties allowed for the primitive integer type
                case ColumnProperty.INT8:
                case ColumnProperty.INT16:
                    column_type = Column.ColumnType.INT;
                    column_property.Add(column_type_string);
                    break;

                // Primitive type long
                case "long":
                    column_type = Column.ColumnType.LONG;
                    break;

                // Properties allowed for the long type
                case ColumnProperty.TIMESTAMP:
                    column_type = Column.ColumnType.LONG;
                    column_property.Add(column_type_string);
                    break;

                // Primitive type float
                case "float":
                    column_type = Column.ColumnType.FLOAT;
                    break;

                // Primitive type double
                case "double":
                    column_type = Column.ColumnType.DOUBLE;
                    break;

                // Primitive type bytes
                case "bytes":
                    column_type = Column.ColumnType.BYTES;
                    break;

                default:
                    throw new KineticaException("Unknown data type/property: " + column_type_string);
                }  // end switch

                // Check if the column is nullable (where the column name is "column_#" as returned by Kinetica)
                if (is_column_nulllable($"column_{i + 1}", dynamic_schema_json))
                {
                    column_property.Add(ColumnProperty.NULLABLE);
                }

                // Now that we have the name, the type and potentially a property for the column,
                // create a Column type and add it to the list
                Column column = new Column(column_name, column_type, column_property);
                columns.Add(column);

                // Also, save the column property in the column name->property map
                column_properties.Add(column_name, column_property);
            }  // end looping over column headers and types


            // Create and return the KineticaType object based on the columns and properties
            return(new KineticaType("", columns, column_properties));
        }  // end fromDynamicSchema()