Ejemplo n.º 1
0
 public override Task <UdtColumnInfo> GetUdtDefinition(string keyspaceName, string typeName)
 {
     return(Cc
            .QueryAsync(string.Format(SelectUdts, keyspaceName, typeName), true)
            .Then(rs =>
     {
         var row = rs.FirstOrDefault();
         if (row == null)
         {
             return TaskHelper.ToTask <UdtColumnInfo>(null);
         }
         var udt = new UdtColumnInfo(row.GetValue <string>("keyspace_name") + "." + row.GetValue <string>("type_name"));
         var fieldTypeTasks = row.GetValue <string[]>("field_types")
                              .Select(name => DataTypeParser.ParseTypeName(_udtResolver, keyspaceName, name))
                              .ToArray();
         return Task.Factory.ContinueWhenAll(fieldTypeTasks, tasks =>
         {
             var ex = tasks.Select(t => t.Exception).FirstOrDefault(e => e != null);
             if (ex != null)
             {
                 throw ex.InnerException;
             }
             var fieldNames = row.GetValue <string[]>("field_names");
             for (var i = 0; i < fieldNames.Length && i < tasks.Length; i++)
             {
                 var field = tasks[i].Result;
                 field.Name = fieldNames[i];
                 udt.Fields.Add(field);
             }
             return udt;
         });
     }));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the definition of a User defined type
        /// </summary>
        public UdtColumnInfo GetUdtDefinition(string keyspace, string typeName)
        {
            var rs  = Query(String.Format(SelectUdts + " WHERE keyspace_name='{0}' AND type_name = '{1}';", keyspace, typeName));
            var row = rs.FirstOrDefault();

            if (row == null)
            {
                return(null);
            }
            var udt        = new UdtColumnInfo(row.GetValue <string>("keyspace_name") + "." + row.GetValue <string>("type_name"));
            var fieldNames = row.GetValue <List <string> >("field_names");
            var fieldTypes = row.GetValue <List <string> >("field_types");

            if (fieldNames.Count != fieldTypes.Count)
            {
                var ex = new DriverInternalError("Field names and types for UDT do not match");
                _logger.Error(ex);
                throw ex;
            }
            for (var i = 0; i < fieldNames.Count; i++)
            {
                var field = TypeCodec.ParseDataType(fieldTypes[i]);
                field.Name = fieldNames[i];
                udt.Fields.Add(field);
            }
            return(udt);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the definition of a User defined type
        /// </summary>
        internal UdtColumnInfo GetUdtDefinition(string typeName)
        {
            var keyspaceName = Name;
            var rs           = _cc.Query(String.Format(SelectUdts, keyspaceName, typeName), true);
            var row          = rs.FirstOrDefault();

            if (row == null)
            {
                return(null);
            }
            var udt        = new UdtColumnInfo(row.GetValue <string>("keyspace_name") + "." + row.GetValue <string>("type_name"));
            var fieldNames = row.GetValue <List <string> >("field_names");
            var fieldTypes = row.GetValue <List <string> >("field_types");

            for (var i = 0; i < fieldNames.Count && i < fieldTypes.Count; i++)
            {
                var field = TypeCodec.ParseDataType(fieldTypes[i]);
                field.Name = fieldNames[i];
                udt.Fields.Add(field);
            }
            return(udt);
        }
Ejemplo n.º 4
0
 public override Task <UdtColumnInfo> GetUdtDefinition(string keyspaceName, string typeName)
 {
     return(Cc
            .QueryAsync(string.Format(SelectUdts, keyspaceName, typeName), true)
            .ContinueSync(rs =>
     {
         var row = rs.FirstOrDefault();
         if (row == null)
         {
             return null;
         }
         var udt = new UdtColumnInfo(row.GetValue <string>("keyspace_name") + "." + row.GetValue <string>("type_name"));
         var fieldNames = row.GetValue <string[]>("field_names");
         var fieldTypes = row.GetValue <string[]>("field_types");
         for (var i = 0; i < fieldNames.Length && i < fieldTypes.Length; i++)
         {
             var field = DataTypeParser.ParseFqTypeName(fieldTypes[i]);
             field.Name = fieldNames[i];
             udt.Fields.Add(field);
         }
         return udt;
     }));
 }
Ejemplo n.º 5
0
        private IColumnInfo GetColumnInfo(FrameReader reader, ColumnTypeCode code)
        {
            ColumnTypeCode innercode;

            switch (code)
            {
            case ColumnTypeCode.List:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                return(new ListColumnInfo
                {
                    ValueTypeCode = innercode,
                    ValueTypeInfo = GetColumnInfo(reader, innercode)
                });

            case ColumnTypeCode.Map:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                IColumnInfo kci        = GetColumnInfo(reader, innercode);
                var         vinnercode = (ColumnTypeCode)reader.ReadUInt16();
                IColumnInfo vci        = GetColumnInfo(reader, vinnercode);
                return(new MapColumnInfo
                {
                    KeyTypeCode = innercode,
                    KeyTypeInfo = kci,
                    ValueTypeCode = vinnercode,
                    ValueTypeInfo = vci
                });

            case ColumnTypeCode.Set:
                innercode = (ColumnTypeCode)reader.ReadUInt16();
                return(new SetColumnInfo
                {
                    KeyTypeCode = innercode,
                    KeyTypeInfo = GetColumnInfo(reader, innercode)
                });

            case ColumnTypeCode.Custom:
                return(new CustomColumnInfo {
                    CustomTypeName = reader.ReadString()
                });

            case ColumnTypeCode.Udt:
                var udtInfo     = new UdtColumnInfo(reader.ReadString() + "." + reader.ReadString());
                var fieldLength = reader.ReadInt16();
                for (var i = 0; i < fieldLength; i++)
                {
                    var dataType = new ColumnDesc
                    {
                        Name     = reader.ReadString(),
                        TypeCode = (ColumnTypeCode)reader.ReadUInt16(),
                    };

                    dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                    udtInfo.Fields.Add(dataType);
                }
                return(udtInfo);

            case ColumnTypeCode.Tuple:
            {
                var tupleInfo     = new TupleColumnInfo();
                var elementLength = reader.ReadInt16();
                for (var i = 0; i < elementLength; i++)
                {
                    var dataType = new ColumnDesc
                    {
                        TypeCode = (ColumnTypeCode)reader.ReadUInt16(),
                    };
                    dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                    tupleInfo.Elements.Add(dataType);
                }
                return(tupleInfo);
            }

            default:
                return(null);
            }
        }
Ejemplo n.º 6
0
        private IColumnInfo GetColumnInfo(BEBinaryReader reader, ColumnTypeCode code)
        {
            ColumnTypeCode innercode;
            switch (code)
            {
                case ColumnTypeCode.List:
                    innercode = (ColumnTypeCode) reader.ReadUInt16();
                    return new ListColumnInfo
                    {
                        ValueTypeCode = innercode,
                        ValueTypeInfo = GetColumnInfo(reader, innercode)
                    };
                case ColumnTypeCode.Map:
                    innercode = (ColumnTypeCode) reader.ReadUInt16();
                    IColumnInfo kci = GetColumnInfo(reader, innercode);
                    var vinnercode = (ColumnTypeCode) reader.ReadUInt16();
                    IColumnInfo vci = GetColumnInfo(reader, vinnercode);
                    return new MapColumnInfo
                    {
                        KeyTypeCode = innercode,
                        KeyTypeInfo = kci,
                        ValueTypeCode = vinnercode,
                        ValueTypeInfo = vci
                    };
                case ColumnTypeCode.Set:
                    innercode = (ColumnTypeCode) reader.ReadUInt16();
                    return new SetColumnInfo
                    {
                        KeyTypeCode = innercode,
                        KeyTypeInfo = GetColumnInfo(reader, innercode)
                    };
                case ColumnTypeCode.Custom:
                    return new CustomColumnInfo { CustomTypeName = reader.ReadString() };
                case ColumnTypeCode.Udt:
                    var udtInfo = new UdtColumnInfo(reader.ReadString() + "." + reader.ReadString());
                    var fieldLength = reader.ReadInt16();
                    for (var i = 0; i < fieldLength; i++)
                    {
                        var dataType = new ColumnDesc
                        {
                            Name = reader.ReadString(),
                            TypeCode = (ColumnTypeCode) reader.ReadUInt16(),
                        };

                        dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                        udtInfo.Fields.Add(dataType);
                    }
                    return udtInfo;
                case ColumnTypeCode.Tuple:
                {
                    var tupleInfo = new TupleColumnInfo();
                    var elementLength = reader.ReadInt16();
                    for (var i = 0; i < elementLength; i++)
                    {
                        var dataType = new ColumnDesc
                        {
                            TypeCode = (ColumnTypeCode) reader.ReadUInt16(),
                        };
                        dataType.TypeInfo = GetColumnInfo(reader, dataType.TypeCode);
                        tupleInfo.Elements.Add(dataType);
                    }
                    return tupleInfo;
                }
                default:
                    return null;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets the definition of a User defined type
 /// </summary>
 public UdtColumnInfo GetUdtDefinition(string keyspace, string typeName)
 {
     var rs = Query(String.Format(SelectUdts + " WHERE keyspace_name='{0}' AND type_name = '{1}';", keyspace, typeName));
     var row = rs.FirstOrDefault();
     if (row == null)
     {
         return null;
     }
     var udt = new UdtColumnInfo(row.GetValue<string>("keyspace_name") + "." + row.GetValue<string>("type_name"));
     var fieldNames = row.GetValue<List<string>>("field_names");
     var fieldTypes = row.GetValue<List<string>>("field_types");
     if (fieldNames.Count != fieldTypes.Count)
     {
         var ex = new DriverInternalError("Field names and types for UDT do not match");
         _logger.Error(ex);
         throw ex;
     }
     for (var i = 0; i < fieldNames.Count; i++)
     {
         var field = TypeCodec.ParseDataType(fieldTypes[i]);
         field.Name = fieldNames[i];
         udt.Fields.Add(field);
     }
     return udt;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the definition of a User defined type
 /// </summary>
 internal UdtColumnInfo GetUdtDefinition(string typeName)
 {
     var keyspaceName = Name;
     var rs = _cc.Query(String.Format(SelectUdts, keyspaceName, typeName), true);
     var row = rs.FirstOrDefault();
     if (row == null)
     {
         return null;
     }
     var udt = new UdtColumnInfo(row.GetValue<string>("keyspace_name") + "." + row.GetValue<string>("type_name"));
     var fieldNames = row.GetValue<List<string>>("field_names");
     var fieldTypes = row.GetValue<List<string>>("field_types");
     for (var i = 0; i < fieldNames.Count && i < fieldTypes.Count; i++)
     {
         var field = TypeCodec.ParseDataType(fieldTypes[i]);
         field.Name = fieldNames[i];
         udt.Fields.Add(field);
     }
     return udt;
 }