@@ -366,22 +366,30 @@ fun SessionContext.pluginDataFrameSchema(coneClassLikeType: ConeClassLikeType):
366366 .mapIndexed { i, symbol -> symbol to coneClassLikeType.typeArguments[i] }
367367 .toMap()
368368
369- var propertySymbols = declarationSymbols.filterIsInstance<FirPropertySymbol >()
370- val annotations = propertySymbols.mapNotNull {
369+ val propertySymbols = declarationSymbols
370+ .filterIsInstance<FirPropertySymbol >()
371+ .sortPropertiesByOrderAnnotation(sessionContext = this )
372+
373+ val columns = propertySymbols.mapNotNull { propertySymbol ->
374+ columnOf(propertySymbol, mapping)
375+ }
376+
377+ return PluginDataFrameSchema (columns)
378+ }
379+
380+ private fun List<FirPropertySymbol>.sortPropertiesByOrderAnnotation (sessionContext : SessionContext ): List <FirPropertySymbol > {
381+ var result = this
382+ val annotations = result.mapNotNull {
371383 val orderArgument = it.getAnnotationByClassId(
372384 Names .ORDER_ANNOTATION ,
373- session
385+ sessionContext. session
374386 )?.argumentMapping?.mapping?.get(Names .ORDER_ARGUMENT )
375387 (orderArgument as ? FirLiteralExpression )?.value as ? Int
376388 }
377- if (propertySymbols.size == annotations.size) {
378- propertySymbols = propertySymbols.zip(annotations).sortedBy { it.second }.map { it.first }
379- }
380- val columns = propertySymbols.mapNotNull { propertySymbol ->
381- columnOf(propertySymbol, mapping)
389+ if (result.size == annotations.size) {
390+ result = result.zip(annotations).sortedBy { it.second }.map { it.first }
382391 }
383-
384- return PluginDataFrameSchema (columns)
392+ return result
385393}
386394
387395private fun KotlinTypeFacade.columnWithPathApproximations (result : FirPropertyAccessExpression ): ColumnsResolver {
@@ -425,6 +433,7 @@ private fun SessionContext.columnOf(it: FirPropertySymbol, mapping: Map<FirTypeP
425433 ?.declaredMemberScope(session, FirResolvePhase .DECLARATIONS )
426434 ?.collectAllProperties()
427435 ?.filterIsInstance<FirPropertySymbol >()
436+ ?.sortPropertiesByOrderAnnotation(this )
428437 ?.mapNotNull { columnOf(it, mapping) }
429438 ? : emptyList()
430439
@@ -438,6 +447,7 @@ private fun SessionContext.columnOf(it: FirPropertySymbol, mapping: Map<FirTypeP
438447 ?.declaredMemberScope(session, FirResolvePhase .DECLARATIONS )
439448 ?.collectAllProperties()
440449 ?.filterIsInstance<FirPropertySymbol >()
450+ ?.sortPropertiesByOrderAnnotation(this )
441451 ?.mapNotNull { columnOf(it, mapping) }
442452 ? : emptyList()
443453 SimpleColumnGroup (name, nestedColumns)
0 commit comments