Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface to replace a null or empty value #14

Open
YongHeeK opened this issue Oct 18, 2021 · 2 comments
Open

Interface to replace a null or empty value #14

YongHeeK opened this issue Oct 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@YongHeeK
Copy link
Contributor

YongHeeK commented Oct 18, 2021

MWE

/Array::array
[a;b;c
null

currently this give us

[
  {"Array" : ["a","b","c"] }, 
  {"Array" : [] }
]

it will be convinient if we give a option to

[
  {"Array" : ["a","b","c"] }, 
  {"Array" : null}
]

Or more general interface of replace certain value would be desired?

@YongHeeK YongHeeK added the enhancement New feature or request label Oct 18, 2021
@YongHeeK
Copy link
Contributor Author

Attribute/A Attribute/B
var null
null var2

currently this give us

[
  {"Attribue" : { "A" : "var", "B": null} },
  {"Attribue" : { "A" : null, "B": "var2"} }
]

it will be convinient if we give a option to

[
  {"Attribue" : { "A" : "var"} },
  {"Attribue" : { "B": "var2"} }
]

@YongHeeK YongHeeK changed the title Remove key if value is null Interface to replace a null or empty value Oct 18, 2021
@YongHeeK
Copy link
Contributor Author

"""
    replace_value!(jws::JSONWorksheet, ::Val{T}, cols::Vector)
'Val{T}'별로 지정된 규칙으로 주어진 값을 변환한다 
'drop_empty': 빈 array '[]' 컬럼을 삭제한다
'empty_to_null': 빈 array '[]'를 'null'로 변경
'drop_nullmember': object에서 value가 'null'인 경우 컬럼 삭제
"""
function replace_value!(jws::JSONWorksheet, ::Val{T}, cols::Vector) where T
    @warn "$(sheetnames(jws))에 정의되지 않은 operation $(T)을 시도했습니다"
end

function replace_value!(jws::JSONWorksheet, ::Val{:drop_empty}, cols::Vector)
    @inbounds for row in jws.data
        for p in JSONPointer.Pointer.(cols)
            row[p] = filter(!isempty, row[p])
        end
    end
end
function replace_value!(jws::JSONWorksheet, ::Val{:empty_to_null}, cols::Vector)
    for row in jws.data
        for p in JSONPointer.Pointer.(cols)
            if isempty(row[p])
                row[p] = missing 
            end
        end
    end
end

function replace_value!(jws::JSONWorksheet, ::Val{:drop_nullmember}, cols::Vector)
    for row in jws.data
        for p in JSONPointer.Pointer.(cols)
            if isa(row[p], AbstractDict)
                for (k, v) in row[p]
                    if isnull(v)
                        delete!(row[p], k)
                    end
                end
            end
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

0 participants