Пример #1
0
        private static int GetExposedElementHeaderSize(IClickHouseTypeInfo elementType)
        {
            var type = elementType;

            while (type.TypeName == "Array")
            {
                type = type.GetGenericArgument(0);
            }

            if (type.TypeName == "LowCardinality")
            {
                return(sizeof(ulong));
            }

            return(0);
        }
Пример #2
0
        public void NamedTupleArguments()
        {
            var typeNames = new[] { "UInt32", "Int64", "Nullable(String)", "Enum16('ok'=0, 'notOk'=8096)", "UInt16", "String", "Float64", "DateTime64(2, 'America/Los_Angeles')", "Nullable(Decimal(28, 4))" };
            var itemNames = new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("A", "A "),
                new KeyValuePair <string, string>("second_item", " second_item "),
                new KeyValuePair <string, string>("B", "`B` "),
                new KeyValuePair <string, string>("_4", "_4 "),
                new KeyValuePair <string, string>("escaped `C` with \\` :)", " `escaped \\`C\\` with \\\\\\` :)` "),
                new KeyValuePair <string, string>(" ([{some other name ", "` ([{some other name ` "),
                new KeyValuePair <string, string>("_O_O_", "   _O_O_    "),
                new KeyValuePair <string, string>("8", " \t`8`\t"),
                new KeyValuePair <string, string>("OMEGA", "\t OMEGA \t")
            };

            Assert.Equal(typeNames.Length, itemNames.Length);

            for (int i = 1; i <= typeNames.Length; i++)
            {
                var tupleItems = Enumerable.Range(0, i).Select(j => itemNames[j].Value + typeNames[j]);
                var typeName   = "Tuple(" + string.Join(',', tupleItems) + ')';
                var typeInfo   = DefaultTypeInfoProvider.Instance.GetTypeInfo(typeName);

                ValidateTypeInfo(typeInfo, i);

                var typeInfoCopy = DefaultTypeInfoProvider.Instance.GetTypeInfo(typeInfo.ComplexTypeName);
                ValidateTypeInfo(typeInfoCopy, i);
            }

            void ValidateTypeInfo(IClickHouseColumnTypeInfo typeInfo, int expectedArgCount)
            {
                Assert.Equal("Tuple", typeInfo.TypeName);
                Assert.Equal(expectedArgCount, typeInfo.GenericArgumentsCount);
                Assert.Equal(expectedArgCount, typeInfo.TypeArgumentsCount);
                for (int i = 0; i < expectedArgCount; i++)
                {
                    IClickHouseTypeInfo baseType = typeInfo.GetGenericArgument(i);
                    Assert.Equal(typeNames[i], baseType.ComplexTypeName);

                    var typeArgument = typeInfo.GetTypeArgument(i);
                    var namedType    = Assert.IsAssignableFrom <KeyValuePair <string, IClickHouseTypeInfo> >(typeArgument);
                    Assert.Equal(itemNames[i].Key, namedType.Key);
                    Assert.Equal(typeNames[i], namedType.Value.ComplexTypeName);
                }
            }
        }
Пример #3
0
        public void TupleGenericArguments()
        {
            var typeNames = new[] { "Decimal(19, 6)", "String", "Nullable(String)", "DateTime64(5, 'Europe/Prague')", "UInt8", "Int32", "Float32", "Enum8('a'=10, 'b'=20)", "UInt64" };

            for (int i = 1; i <= typeNames.Length; i++)
            {
                var typeName = "Tuple(" + string.Join(',', typeNames.Take(i)) + ')';
                var typeInfo = DefaultTypeInfoProvider.Instance.GetTypeInfo(typeName);

                Assert.Equal(i, typeInfo.GenericArgumentsCount);
                Assert.Equal(i, typeInfo.TypeArgumentsCount);
                for (int j = 0; j < i; j++)
                {
                    IClickHouseTypeInfo baseType = typeInfo.GetGenericArgument(j);
                    Assert.Equal(typeNames[j], baseType.ComplexTypeName);

                    var typeArgument = typeInfo.GetTypeArgument(j);
                    baseType = Assert.IsAssignableFrom <IClickHouseTypeInfo>(typeArgument);
                    Assert.Equal(typeNames[j], baseType.ComplexTypeName);
                }
            }
        }