|
| 1 | +from datetime import date |
1 | 2 | import itertools |
2 | 3 | import substrait.gen.proto.algebra_pb2 as stalg |
3 | 4 | import substrait.gen.proto.type_pb2 as stp |
@@ -41,6 +42,36 @@ def resolve(base_schema: stp.NamedStruct, registry: ExtensionRegistry) -> stee.E |
41 | 42 | literal = stalg.Expression.Literal(fp64=value, nullable=type.fp64.nullability == stp.Type.NULLABILITY_NULLABLE) |
42 | 43 | elif kind == "string": |
43 | 44 | literal = stalg.Expression.Literal(string=value, nullable=type.string.nullability == stp.Type.NULLABILITY_NULLABLE) |
| 45 | + elif kind == "binary": |
| 46 | + literal = stalg.Expression.Literal(binary=value, nullable=type.binary.nullability == stp.Type.NULLABILITY_NULLABLE) |
| 47 | + elif kind == "date": |
| 48 | + date_value = (value - date(1970,1,1)).days if isinstance(value, date) else value |
| 49 | + literal = stalg.Expression.Literal(date=date_value, nullable=type.date.nullability == stp.Type.NULLABILITY_NULLABLE) |
| 50 | + # TODO |
| 51 | + # IntervalYearToMonth interval_year_to_month = 19; |
| 52 | + # IntervalDayToSecond interval_day_to_second = 20; |
| 53 | + # IntervalCompound interval_compound = 36; |
| 54 | + elif kind == "fixed_char": |
| 55 | + literal = stalg.Expression.Literal(fixed_char=value, nullable=type.fixed_char.nullability == stp.Type.NULLABILITY_NULLABLE) |
| 56 | + elif kind == "varchar": |
| 57 | + literal = stalg.Expression.Literal( |
| 58 | + var_char=stalg.Expression.Literal.VarChar(value=value, length=type.varchar.length), |
| 59 | + nullable=type.varchar.nullability == stp.Type.NULLABILITY_NULLABLE |
| 60 | + ) |
| 61 | + elif kind == "fixed_binary": |
| 62 | + literal = stalg.Expression.Literal(fixed_binary=value, nullable=type.fixed_binary.nullability == stp.Type.NULLABILITY_NULLABLE) |
| 63 | + # TODO |
| 64 | + # Decimal decimal = 24; |
| 65 | + # PrecisionTime precision_time = 37; // Time in precision units past midnight. |
| 66 | + # PrecisionTimestamp precision_timestamp = 34; |
| 67 | + # PrecisionTimestamp precision_timestamp_tz = 35; |
| 68 | + # Struct struct = 25; |
| 69 | + # Map map = 26; |
| 70 | + # bytes uuid = 28; |
| 71 | + # Type null = 29; // a typed null literal |
| 72 | + # List list = 30; |
| 73 | + # Type.List empty_list = 31; |
| 74 | + # Type.Map empty_map = 32; |
44 | 75 | else: |
45 | 76 | raise Exception(f"Unknown literal type - {type}") |
46 | 77 |
|
|
0 commit comments