Exemplo n.º 1
0
 public override TypedArrayWrapper CreateTypedArrayWrapper(Array array, bool isNullable)
 {
     if (isNullable)
     {
         return(TypedArrayWrapper.Create <TSystemType?>(array));
     }
     return(TypedArrayWrapper.Create <TSystemType>(array));
 }
Exemplo n.º 2
0
        internal Array PackDefinitions(int maxDefinitionLevel, out int[] pooledDefinitionLevels, out int definitionLevelCount)
        {
            pooledDefinitionLevels = ArrayPool <int> .Shared.Rent(Data.Length);

            definitionLevelCount = Data.Length;

            if (!Field.HasNulls)
            {
                SetPooledDefinitionLevels(maxDefinitionLevel, pooledDefinitionLevels);
                return(Data);
            }

            //get count of nulls
            int  nullCount  = 0;
            bool isNullable = Field.ClrType.IsNullable() || Data.GetType().GetElementType().IsNullable();

            TypedArrayWrapper typedData = _dataTypeHandler.CreateTypedArrayWrapper(Data, isNullable);

            for (int i = 0; i < Data.Length; i++)
            {
                bool isNull = typedData.GetValue(i) == null;
                if (isNull)
                {
                    nullCount += 1;
                }
            }

            // if the field definition said there could be nulls, but weren't, don't incur the overhead of new array allocations and item copying
            if (nullCount == 0)
            {
                SetPooledDefinitionLevels(maxDefinitionLevel, pooledDefinitionLevels);
                return(Data);
            }

            //pack
            Array             result      = _dataTypeHandler.GetArray(Data.Length - nullCount, false, false);
            TypedArrayWrapper typedResult = _dataTypeHandler.CreateTypedArrayWrapper(result, false);

            int ir = 0;

            for (int i = 0; i < Data.Length; i++)
            {
                object value = typedData.GetValue(i);

                if (value == null)
                {
                    pooledDefinitionLevels[i] = 0;
                }
                else
                {
                    pooledDefinitionLevels[i] = maxDefinitionLevel;
                    typedResult.SetValue(value, ir++);
                }
            }
            return(result);
        }
 public virtual TypedArrayWrapper CreateTypedArrayWrapper(Array array, bool isNullable)
 {
     return(TypedArrayWrapper.Create <TSystemType>(array));
 }