Skip to content

Support casting to/from text for datums and float64s, respectively#1086

Merged
quodlibetor merged 2 commits intoMaterializeInc:masterfrom
quodlibetor:support-text-casts
Nov 26, 2019
Merged

Support casting to/from text for datums and float64s, respectively#1086
quodlibetor merged 2 commits intoMaterializeInc:masterfrom
quodlibetor:support-text-casts

Conversation

@quodlibetor
Copy link
Contributor

No description provided.

This is how it works in postgres
}

pub fn cast_datum_to_string<'a>(a: Datum<'a>) -> Datum<'a> {
let owned = |v: String| Datum::String(Cow::Owned(v));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nice!

I had added cow_from_str to the Datum impl in a previous PR. Would it make sense to add this there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that conceptually this is doing a slightly slightly different, although the fact that it matches on every kind of datum makes it look like it belongs in there.

Datum::Bytes(_) => unreachable!("bytes should be caught in the cast match"),
Datum::String(v) => Datum::String(v),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general rule there shouldn't be any type matching in func.rs, since the correct function can be selected ahead of time by the SQL planner. We've slipped on this rule in a few places, so fine to merge as is and I'll come through and clean it up later! (But if you're up for it, great!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm reading your comment correctly then originally I had something more like what you're requesting: I had a separate Cast___ToString method variants and equivalent methods for everything, but since each seemed to be identical I thought this would get us every cast in one fell swoop.

I see what you mean about this violating the pattern, though. I'm pretty happy to clean this up in a follow up commit, what are the benefits to this pattern? Is it mostly the code hygiene, or are there other things as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it means that we don't need to have a branch in the main code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well there'd still be the branch, but it'd by highly predictable.

UnaryFunc::CastDateToTimestamp => f.write_str("datetots"),
UnaryFunc::CastDateToTimestampTz => f.write_str("datetotstz"),
UnaryFunc::CastTimestampToTimestampTz => f.write_str("tstotstz"),
UnaryFunc::CastDatumToString => f.write_str("f64tostring"),
Copy link
Contributor

Choose a reason for hiding this comment

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

s/f64tostring/datumtostring/

@benesch
Copy link
Contributor

benesch commented Nov 26, 2019 via email

This punts on decimals and bytes because of mild inconvenience and not knowing what the
output should be, respectively.
@quodlibetor
Copy link
Contributor Author

Okay, I'll improve that in a follow up, I'd like to get my grafana changes landed first.

@quodlibetor quodlibetor merged commit bbe963c into MaterializeInc:master Nov 26, 2019
@quodlibetor quodlibetor deleted the support-text-casts branch November 26, 2019 19:39
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.

3 participants