@@ -821,10 +821,21 @@ class Modify : TestBase() {
821
821
// SampleEnd
822
822
}
823
823
824
+ private class CityInfo (val city : String? , val population : Int , val location : String )
825
+ private fun queryCityInfo (city : String? ): CityInfo { return CityInfo (city, city?.length ? : 0 , " 35.5 32.2" ) }
826
+
824
827
@Test
825
- fun addCalculated () {
828
+ fun addCalculatedApi () {
829
+ // SampleStart
826
830
class CityInfo (val city : String? , val population : Int , val location : String )
827
- fun queryCityInfo (city : String? ): CityInfo { return CityInfo (city, city?.length ? : 0 , " 35.5 32.2" ) }
831
+ fun queryCityInfo (city : String? ): CityInfo {
832
+ return CityInfo (city, city?.length ? : 0 , " 35.5 32.2" )
833
+ }
834
+ // SampleEnd
835
+ }
836
+
837
+ @Test
838
+ fun addCalculated_properties () {
828
839
// SampleStart
829
840
val personWithCityInfo = df.add {
830
841
val cityInfo = city.map { queryCityInfo(it) }
@@ -837,6 +848,35 @@ class Modify : TestBase() {
837
848
personWithCityInfo[" cityInfo" ][" population" ] shouldBe df.city.map { it?.length ? : 0 }.named(" population" )
838
849
}
839
850
851
+ @Test
852
+ fun addCalculated_accessors () {
853
+ // SampleStart
854
+ val city by column<String ?>()
855
+ val personWithCityInfo = df.add {
856
+ val cityInfo = city().map { queryCityInfo(it) }
857
+ " cityInfo" {
858
+ cityInfo.map { it.location } into CityInfo ::location
859
+ cityInfo.map { it.population } into " population"
860
+ }
861
+ }
862
+ // SampleEnd
863
+ personWithCityInfo[" cityInfo" ][" population" ] shouldBe df.city.map { it?.length ? : 0 }.named(" population" )
864
+ }
865
+
866
+ @Test
867
+ fun addCalculated_strings () {
868
+ // SampleStart
869
+ val personWithCityInfo = df.add {
870
+ val cityInfo = " city" <String ?>().map { queryCityInfo(it) }
871
+ " cityInfo" {
872
+ cityInfo.map { it.location } into CityInfo ::location
873
+ cityInfo.map { it.population } into " population"
874
+ }
875
+ }
876
+ // SampleEnd
877
+ personWithCityInfo[" cityInfo" ][" population" ] shouldBe df.city.map { it?.length ? : 0 }.named(" population" )
878
+ }
879
+
840
880
@Test
841
881
fun addMany_properties () {
842
882
// SampleStart
0 commit comments