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

replace cast string to fixed function in driver.cpp #2221

Merged
merged 1 commit into from
Oct 17, 2023
Merged

replace cast string to fixed function in driver.cpp #2221

merged 1 commit into from
Oct 17, 2023

Conversation

AEsir777
Copy link
Contributor

@AEsir777 AEsir777 commented Oct 16, 2023

ToDo

  • add more tests
  • fixed float conversion bug (probably just because the digits are full)
  • error message
new old
FLOAT(20) x 100000 5194.5 7127.13200

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (5ce92b8) 89.57% compared to head (731a42c) 89.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2221      +/-   ##
==========================================
- Coverage   89.57%   89.56%   -0.02%     
==========================================
  Files        1006     1006              
  Lines       36273    36313      +40     
==========================================
+ Hits        32493    32523      +30     
- Misses       3780     3790      +10     
Files Coverage Δ
...rocessor/operator/persistent/reader/csv/driver.cpp 97.72% <100.00%> (+0.59%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


template<>
void copyStringToVector(ValueVector* vector, uint64_t rowToAdd, std::string_view strVal,
const CSVReaderConfig& csvReaderConfig, int16_t value) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casting for numeric types are very similar: You can implement the casting for numeric types in the template function body, and use specialization for other types. So you don't need to duplicate the code for numeric type casting.
The numeric type casting:

 if (strVal.empty() || isNull(strVal)) {
        vector->setNull(rowToAdd, true /* isNull */);
        return;
    } else {
        vector->setNull(rowToAdd, false /* isNull */);
    }

    function::simpleIntegerCast<T>(
        strVal.data(), strVal.length(), value, vector->getDataType());
    vector->setValue(rowToAdd, value);

Using this generic templated numeric type casting function, you don't need to duplicate the common code for all numeric types.
Anyways, feel free to ping me if you have questions regarding to the refactor. Or you can leave it to me.

src/processor/operator/persistent/reader/csv/driver.cpp Outdated Show resolved Hide resolved
@AEsir777 AEsir777 merged commit fc71a74 into master Oct 17, 2023
12 checks passed
@AEsir777 AEsir777 deleted the cast branch October 17, 2023 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants