@@ -158,19 +158,19 @@ impl DataScopeRef {
158158#[ pyclass]
159159#[ derive( Debug , Clone ) ]
160160pub struct DataType {
161- typ : schema:: EnrichedValueType ,
161+ schema : schema:: EnrichedValueType ,
162162}
163163
164164impl From < schema:: EnrichedValueType > for DataType {
165- fn from ( typ : schema:: EnrichedValueType ) -> Self {
166- Self { typ }
165+ fn from ( schema : schema:: EnrichedValueType ) -> Self {
166+ Self { schema }
167167 }
168168}
169169
170170#[ pymethods]
171171impl DataType {
172172 pub fn __str__ ( & self ) -> String {
173- format ! ( "{}" , self . typ )
173+ format ! ( "{}" , self . schema )
174174 }
175175
176176 pub fn __repr__ ( & self ) -> String {
@@ -201,7 +201,7 @@ impl DataSlice {
201201 }
202202
203203 pub fn field ( & self , field_name : & str ) -> PyResult < Option < DataSlice > > {
204- let field_schema = match & self . data_type . typ . typ {
204+ let field_schema = match & self . data_type . schema . typ {
205205 schema:: ValueType :: Struct ( struct_type) => {
206206 match struct_type. fields . iter ( ) . find ( |f| f. name == field_name) {
207207 Some ( field) => field,
@@ -232,7 +232,7 @@ impl DataSlice {
232232 . map ( |f| f. spec . clone ( ) )
233233 . ok_or_else ( || PyException :: new_err ( format ! ( "field {} not found" , field_name) ) ) ?,
234234
235- spec:: ValueMapping :: Literal { .. } => {
235+ spec:: ValueMapping :: Constant { .. } => {
236236 return Err ( PyException :: new_err (
237237 "field access not supported for literal" ,
238238 ) )
@@ -277,7 +277,7 @@ impl std::fmt::Display for DataSlice {
277277 write ! (
278278 f,
279279 "DataSlice({}; {} {}) " ,
280- self . data_type. typ , self . scope, self . value
280+ self . data_type. schema , self . scope, self . value
281281 ) ?;
282282 Ok ( ( ) )
283283 }
@@ -420,6 +420,24 @@ impl FlowBuilder {
420420 Ok ( result)
421421 }
422422
423+ pub fn constant < ' py > (
424+ & self ,
425+ value_type : py:: Pythonized < schema:: EnrichedValueType > ,
426+ value : Bound < ' py , PyAny > ,
427+ ) -> PyResult < DataSlice > {
428+ let schema = value_type. into_inner ( ) ;
429+ let value = py:: value_from_py_object ( & schema. typ , & value) ?;
430+ let slice = DataSlice {
431+ scope : self . root_data_scope_ref . clone ( ) ,
432+ value : Arc :: new ( spec:: ValueMapping :: Constant ( spec:: ConstantMapping {
433+ schema : schema. clone ( ) ,
434+ value : serde_json:: to_value ( value) . into_py_result ( ) ?,
435+ } ) ) ,
436+ data_type : schema. into ( ) ,
437+ } ;
438+ Ok ( slice)
439+ }
440+
423441 pub fn add_direct_input (
424442 & mut self ,
425443 name : String ,
@@ -533,7 +551,7 @@ impl FlowBuilder {
533551 . into_iter ( )
534552 . map ( |( name, ds) | FieldSchema {
535553 name,
536- value_type : ds. data_type . typ ,
554+ value_type : ds. data_type . schema ,
537555 } )
538556 . collect ( ) ,
539557 ) ,
@@ -600,7 +618,7 @@ impl FlowBuilder {
600618 scope : None ,
601619 field_path : spec:: FieldPath ( vec ! [ field_name. to_string( ) ] ) ,
602620 } ) ) ,
603- data_type : DataType { typ : field_type } ,
621+ data_type : DataType { schema : field_type } ,
604622 } ) )
605623 }
606624
0 commit comments