Skip to content

Commit

Permalink
fix broken -x option of zsv select (#133)
Browse files Browse the repository at this point in the history
* fix broken -x option of zsv select
* add test
* update for select-pull as well
  • Loading branch information
liquidaty committed Jul 21, 2023
1 parent d56ade5 commit 5c22aae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 0 additions & 3 deletions app/select-pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,6 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
arg_i++;
if(!(arg_i < argc))
stat = zsv_printerr(1, "%s option requires a value", argv[arg_i-1]);
else if(zsv_select_column_index_selection((const unsigned char *)argv[arg_i], NULL, NULL) ==
zsv_select_column_index_selection_type_none)
stat = zsv_printerr(1, "%s option: invalid value %s (expected number or number range e.g. 8 or 8-12)", argv[arg_i-1], argv[arg_i]);
else
zsv_select_add_exclusion(&data, argv[arg_i]);
} else if(*argv[arg_i] == '-')
Expand Down
4 changes: 1 addition & 3 deletions app/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ static inline unsigned char *zsv_select_get_header_name(struct zsv_select_data *

static inline char zsv_select_excluded_current_header_name(struct zsv_select_data *data, unsigned in_ix) {
if(data->exclusion_count) {
// to do: cache this result
unsigned char *header_name = zsv_select_get_header_name(data, in_ix);
if(header_name) {
for(unsigned int i = 0; i < data->exclusion_count; i++)
Expand Down Expand Up @@ -858,9 +859,6 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
arg_i++;
if(!(arg_i < argc))
stat = zsv_printerr(1, "%s option requires a value", argv[arg_i-1]);
else if(zsv_select_column_index_selection((const unsigned char *)argv[arg_i], NULL, NULL) ==
zsv_select_column_index_selection_type_none)
stat = zsv_printerr(1, "%s option: invalid value %s (expected number or number range e.g. 8 or 8-12)", argv[arg_i-1], argv[arg_i]);
else
zsv_select_add_exclusion(&data, argv[arg_i]);
} else if(*argv[arg_i] == '-')
Expand Down
3 changes: 3 additions & 0 deletions app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ test-n-select test-n-select-pull: test-n-% : ${BUILD_DIR}/bin/zsv_%${EXE}
@${PREFIX} $< ${TEST_DATA_DIR}/loans_1.csv -u "?" -R 4 -d 2 ${REDIRECT} ${TMP_DIR}/test-n-$*.out
@${CMP} ${TMP_DIR}/test-n-$*.out expected/test-select.out && ${TEST_PASS} || ${TEST_FAIL}

@${PREFIX} $< ${TEST_DATA_DIR}/loans_1.csv -u "?" -H 10 -R 4 -d 2 -x 'Cash Out Amount' ${REDIRECT} ${TMP_DIR}/test-n-$*-x.out
@${CMP} ${TMP_DIR}/test-n-$*-x.out expected/test-select-x.out && ${TEST_PASS} || ${TEST_FAIL}

@${PREFIX} $< ${TEST_DATA_DIR}/test/embedded.csv -e 'X' ${REDIRECT} ${TMP_DIR}/test-2-$*.out
@${CMP} ${TMP_DIR}/test-2-$*.out expected/test-2-select.out && ${TEST_PASS} || ${TEST_FAIL}

Expand Down
11 changes: 11 additions & 0 deletions app/test/expected/test-select-x.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
useful data --> useful data -->,,Primary Servicer,ServicingFee %,ServicingFee? Flatdollar,ServicingAdvance Methodology,Originator,Loan Group,Loan Number,Amortization Type,Lien Position,HELOC Indicator,,Loan Purpose,Total Origination and Discount Points,Covered/High Cost Loan Indicator,Relocation Loan Indicator,Broker Indicator,Channel,Escrow Indicator,Senior Loan Amount(s),Loan Type of Most Senior Lien,,Hybrid PeriodofMost Senior Lien (inmonths),Neg Am Limit ofMost Senior Lien,Junior MortgageBalance,Origination Date ofMost Senior Lien,Origination Date,Original LoanAmount,Original InterestRate,OriginalAmortization Term,Original Term toMaturity,First Payment Dateof Loan,,Interest Type Indicator,Original Interest Only Term,Buy Down Period,HELOC Draw Period,Current Loan Amount,Current Interest Rate,Current Payment Amount Due,Interest Paid Through Date,Current Payment Status,Index Type,,ARM Look-backDays,Gross Margin,ARM Round Flag,ARM Round Factor,Initial Fixed RatePeriod,Initial Interest RateCap (Change Up),Initial Interest RateCap (Change Down),Subsequent InterestRate Reset Period,Subsequent InterestRate Cap (Change Down),Subsequent InterestRate Cap (ChangeUp),,Lifetime MaximumRate (Ceiling),Lifetime MinimumRate (Floor),NegativeAmortization Limit,Initial NegativeAmortization RecastPeriod,SubsequentNegativeAmortization RecastPeriod,Initial FixedPayment Period,SubsequentPayment ResetPeriod,Initial PeriodicPayment Cap,SubsequentPeriodic PaymentCap,Initial MinimumPayment ResetPeriod,,SubsequentMinimum PaymentReset Period,Option ARMIndicator,Options at Recast,Initial MinimumPayment,Current MinimumPayment,Prepayment PenaltyCalculation,Prepayment PenaltyType,Prepayment PenaltyTotal Term,Prepayment PenaltyHard Term,Primary Borrower ID,,Number ofMortgagedProperties,Total Number ofBorrowers,Self-employmentFlag,Current ?Other?Monthly Payment,Length ofEmployment:Borrower,Length ofEmployment: Co-Borrower,Years in Home,FICO Model Used,Most Recent FICODate,Primary WageEarner OriginalFICO: Equifax,,Primary WageEarner OriginalFICO: Experian,Primary WageEarner OriginalFICO: TransUnion,Secondary WageEarner OriginalFICO: Equifax,Secondary WageEarner OriginalFICO: Experian,Secondary WageEarner OriginalFICO: TransUnion,OriginalPrimary BorrowerFICO,Most RecentPrimary BorrowerFICO,Most Recent Co-Borrower FICO,Most Recent FICOMethod,VantageScore:Primary Borrower,,VantageScore: Co-Borrower,Most RecentVantageScoreMethod,VantageScore Date,Credit Report:Longest Trade Line,Credit Report:Maximum TradeLine,Credit Report:Number of TradeLines,Credit Line UsageRatio,Most Recent 12-month Pay History,Months Bankruptcy,Months Foreclosure,,Primary BorrowerWage Income,Co-Borrower WageIncome,Primary BorrowerOther Income,Co-Borrower OtherIncome,All Borrower WageIncome,All Borrower TotalIncome,4506-T Indicator,Borrower IncomeVerification Level,Co-BorrowerIncome Verification,BorrowerEmploymentVerification,,Co-BorrowerEmploymentVerification,Borrower AssetVerification,Co-Borrower AssetVerification,Liquid / CashReserves,Monthly Debt AllBorrowers,Originator DTI,Fully Indexed Rate,QualificationMethod,Percentage of DownPayment fromBorrower OwnFunds,,City,State,Postal Code,Property Type,Occupancy,Sales Price,Original AppraisedProperty Value,Original PropertyValuation Type,Original PropertyValuation Date,,OriginalAutomated Valuation Model (AVM) Model Name,OriginalAVM Confidence Score,MostRecent Property Value2,MostRecent Property Valuation Type,MostRecent Property Valuation Date,MostRecent AVM ModelName,MostRecent AVM Confidence Score,OriginalCLTV,OriginalLTV,OriginalPledged Assets,MortgageInsurance CompanyName,Mortgage Insurance Percent,,MI: Lender orBorrower Paid?,Pool Insurance Co.Name,Pool Insurance StopLoss %,MI CertificateNumber,Updated DTI(Front-end),Updated DTI(Back-end),ModificationEffective PaymentDate,Total CapitalizedAmount,Total DeferredAmount,Pre- ModificationInterest (Note) Rate,,Pre- Modification P&IPayment,Pre- ModificationInitial Interest RateChange DownwardCap,Pre- ModificationSubsequent InterestRate Cap,Pre- ModificationNext Interest RateChange Date,Pre- Modification I/OTerm,Forgiven PrincipalAmount,Forgiven InterestAmount,Number ofModifications,Cash To/From Brrw at Closing,Brrw - Yrs at in Industry,,CoBrrw - Yrs at in Industry,Junior Mortgage Drawn Amount,Maturity Date,PrimaryBorrower Wage Income (Salary),PrimaryBorrower Wage Income (Bonus),PrimaryBorrower Wage Income (Commission),Co-Borrower Wage Income (Salary),,Co-Borrower Wage Income (Bonus),Co-Borrower Wage Income (Commission),Originator Doc Code,Income Verification,Asset Verification
useful data -->,1,1002338,0.0025,,,1002338,Group 1,978000019,2,1,0,1,9,,,,,1,0,0,,1,,,0,,20111025,1000000,0.042,360,360,20111201,1,1,120,0,,"1,000,000.00",0.042,3500,20130101,0,35,1,45,0.01625,3,0.00125,120,0.05,0.05,1,0,0,1,0.092,0.029,,,,,,,,,1,,,,,,99,99,60,,58,1,1,,1,,14,0,7,1,20121212,,1,,,,,,801,789,,3,,1,,,,,,,,0,,,1,6193,0,5155,0,6193,11348,0,5,,2,1,,3,,966841.81,4530.12,0.3992,,,,1,Vancouver,WA,98661,2,1,,1740000,3,20110914,1,,,,,,,,0.5747,0.5747,0,0,0,1,,,,,,,,,,,1,,,,,,,,,,14,1,0,0,20411101,6193,0,0,0,1,0,,Full,Two Years,One Month
useful data -->,2,1002338,0.0025,,,1002338,Group 1,978000078,2,1,0,2,7,,,,,1,0,0,,2,,,280000,,20110707,1000000,0.0415,360,360,20110901,2,1,120,0,,"1,000,000.00",0.0415,3458.33,20130101,0,35,2,45,0.01625,3,0.00125,120,0.05,0.05,1,0,0,2,0.0915,0.029,,,,,,,,,2,,,,,,99,99,60,,455,2,3,,0,,15,3,0,1,20121212,,2,,,,,,788,788,,3,,2,,,,,,,,0,,,2,8333.33,7002,10870.56,0,15335.33,26205.97,0,5,,2,2,,4,,4942401.6,7337.67,0.28,,,100,2,KELSO,WA,98626,1,1,1600000,1700000,3,20110602,2,,,,,,,,0.8,0.625,0,0,0,2,,,,,,,,,,,2,,,,,,,,,,15,2,4,280000,20410801,8333,0,0,7002,2,0,0,Full,Two Years,Two Months
,3,1000383,0.0025,,,9999999,Group 1,1000001102,2,1,0,3,9,,,,,1,0,0,,3,,,57500,,20111024,502500,0.04625,360,360,20111201,3,1,0,0,,"493,213.96",0.04625,2583.55,20130101,0,39,3,45,0.0275,3,0.00125,120,0.05,0.05,12,0.02,0.02,3,0.09625,0.0275,,,,,,,,,3,,,,,,,,0,,364,3,1,,1,,0.5,3.8,4,1,20121212,,3,,,,,,762,743,,3,,3,,,,,,,,0,,,3,6229.17,7355.79,0,0,13584.96,13584.96,1,5,,3,3,,4,,67201.4,5879.57,0.4328,,,,3,Olympia,WA,98502,7,1,,670000,3,20110906,3,,,,,,,,0.8358,0.75,0,0,0,3,,,,,,,,,,,3,,,,,,,,,,12,3,3.8,57500,20411101,6229.17,0,0,7355.79,3,0,0,Full,Two Years,Two Months
,4,1000383,0.0025,,,9999999,Group 1,1010007709,1,1,0,4,9,,,,,1,0,0,,4,,,250000,,20121023,715000,0.035,180,180,20121201,4,1,0,0,,"708,939.19",0.035,5111.41,20130101,0,,4,,,,,,,,,,,4,,,,,,,,,,,4,,,,,,,,0,,420,4,2,,0,,11,,2,1,,,4,,,,,,772,,,,,4,,,,,,,,0,,,4,25781.25,0,0,0,25781.25,25781.25,1,5,,3,4,,4,,196542.45,8405.41,0.326028,,,,4,GIG HARBOR,WA,98332,1,1,,2100000,3,20121003,4,,,,,,,,0.4595,0.3404,0,0,0,4,,,,,,,,,,,4,,,,,,,,,,12,4,,130389,20271101,25781.25,0,0,0,4,0,0,Full,Two Years,Two Months
,5,1000383,0.0025,,,9999999,Group 1,1030004301,1,1,0,5,9,,,,,2,0,0,,5,,,0,,20120911,694000,0.035,180,180,20121101,5,1,0,0,,"685,162.93",0.035,4961.28,20130101,0,,5,,,,,,,,,,,5,,,,,,,,,,,5,,,,,,,,0,,202,5,1,,1,,8.5,,9,1,,,5,,,,,,767,,,,,5,,,,,,,,0,,,5,24723,0,0,0,24723,24723,1,5,,3,5,,4,,652220.12,8687.54,0.351395,,,,5,MARYSVILLE,WA,98271,1,1,,900000,3,20120419,5,,,,,,,,0.7711,0.7711,0,0,0,5,,,,,,,,,,,5,,,,,,,,,,25,5,,0,20271001,24723,0,0,0,5,0,0,Full,Two Years,Two Months
,6,1000383,0.0025,,,9999999,Group 1,1030006057,1,1,0,6,9,,,,,1,0,0,,6,,,0,,20120830,770000,0.035,180,180,20121101,6,1,0,0,,"760,195.16",0.035,5504.6,20130101,0,,6,,,,,,,,,,,6,,,,,,,,,,,6,,,,,,,,0,,404,6,3,,1,,33,33,4,1,,,6,,,,,,797,,,,,6,,,,,,,,0,,,6,269436.19,269436.19,0,0,538872.38,538872.38,1,5,,3,6,,4,,861493.44,50769.32,0.094214,,,,6,Seattle,WA,98144,7,1,,1100000,3,20120710,6,,,,,,,,0.7,0.7,0,0,0,6,,,,,,,,,,,6,,,,,,,,,,33,6,33,0,20271001,269436.19,0,0,269436.19,6,0,0,Full,Two Years,Two Months
,7,1000383,0.0025,,,9999999,Group 1,1030006720,1,1,0,7,9,,,,,2,0,0,,7,,,0,,20120920,499000,0.0375,180,180,20121101,7,1,0,0,,"492,772.21",0.0375,3628.84,20130101,0,,7,,,,,,,,,,,7,,,,,,,,,,,7,,,,,,,,0,,261,7,1,,0,,1,6,6,1,,,7,,,,,,755,,,,,7,,,,,,,,0,,,7,11030.79,2228.3,0,0,13259.09,13259.09,1,5,,3,7,,4,,92527.8,5554.35,0.418909,,,,7,Seattle,WA,98117,7,1,,885000,3,20120811,7,,,,,,,,0.5638,0.5638,0,0,0,7,,,,,,,,,,,7,,,,,,,,,,16,7,6,0,20271001,11030.79,0,0,2228.3,7,0,0,Full,Two Years,Two Months
,8,1000383,0.0025,,,9999999,Group 1,1030006758,1,1,0,8,9,,,,,2,0,0,,8,,,0,,20120925,800000,0.0325,180,180,20121101,8,1,0,0,,"789,528.78",0.0325,5621.35,20130101,0,,8,,,,,,,,,,,8,,,,,,,,,,,8,,,,,,,,0,,373,8,3,,1,,15,,3,1,,,8,,,,,,786,,,,,8,,,,,,,,0,,,8,22253.77,0,0,0,22253.77,22253.77,1,5,,3,8,,4,,323064.33,7755.17,0.348488,,,,8,Seattle,WA,98112,7,1,,1400000,3,20120912,8,,,,,,,,0.5714,0.5714,0,0,0,8,,,,,,,,,,,8,,,,,,,,,,15,8,,0,20271001,22253.77,0,0,0,8,0,0,Full,Two Years,Two Months
,9,1000383,0.0025,,,1000536,Group 1,1050004792,1,1,0,9,9,,,,,1,4,0,,9,,,0,,20120906,534500,0.03625,180,180,20121101,9,1,0,0,,"527,761.78",0.03625,3853.94,20130101,0,,9,,,,,,,,,,,9,,,,,,,,,,,9,,,,,,,,0,,340,9,4,,1,,28,13,5,1,,,9,,,,,,713,,,,,9,,,,,,,,0,,,9,14443.67,3375,0,0,17818.67,17818.67,1,5,,3,9,,4,,139301.33,7264.05,0.407665,,,,9,WOODINVILLE,WA,98077,7,1,,820000,3,20120703,9,,,,,,,,0.6518,0.6518,0,0,0,9,,,,,,,,,,,9,,,,,,,,,,28,9,13,0,20271001,14443.67,0,0,3375,9,0,0,Full,Two Years,Two Months
,10,1000383,0.0025,,,1000536,Group 1,1050005552,1,1,0,10,9,,,,,1,0,0,,10,,,0,,20120904,650000,0.03375,180,180,20121101,10,1,0,0,,"641,640.11",0.03375,4606.94,20130101,0,,10,,,,,,,,,,,10,,,,,,,,,,,10,,,,,,,,0,,277,10,2,,0,,8.5,,1.5,1,,,10,,,,,,778,,,,,10,,,,,,,,0,,,10,26608.5,0,0,0,26608.5,26608.5,1,5,,3,10,,4,,163487.07,11287.46,0.424205,,,,10,SAMMAMISH,WA,98075,1,1,,1300000,3,20120727,10,,,,,,,,0.5,0.5,0,0,0,10,,,,,,,,,,,10,,,,,,,,,,13,10,,0,20271001,26608.5,0,0,0,10,0,0,Full,Two Years,Two Months

0 comments on commit 5c22aae

Please sign in to comment.