Skip to content

Conversation

dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Apr 3, 2025

What changes were proposed in this pull request?

This PR aims to add CaseInsensitiveDictionary and use it in the following classes.

  • DataFrameReader
  • DataFrameWriter

Why are the changes needed?

For feature parity.

Does this PR introduce any user-facing change?

No, this is a new addition to the unreleased version.

How was this patch tested?

Pass the CIs.

Was this patch authored or co-authored using generative AI tooling?

No.

@dongjoon-hyun
Copy link
Member Author

Could you review this PR when you have some time, @LuciferYang ?

@LuciferYang
Copy link

Sure, I'll take a look at it later.

@dongjoon-hyun
Copy link
Member Author

Thank you so much. Take your time~


dict["key3"] = 2025
#expect(dict.count == 3)
#expect(dict["key3"] as! Int == 2025)

Choose a reason for hiding this comment

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

Is the scenario where dict["key3"] = nil is supported as expected? I tested it, and the result seems to be correct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the removal of keys are working as you expected.

Initially, I thought you are saying that supporting nil as a valid value. That is not supported because we are using [String: Sendable] type. To support nil as a value, we need to use [String: Sendable?].

Anyway, you are right in terms of the removal of keys. I accepted all the other code suggestions too.

}

public func toStringDictionary() -> [String: String] {
var dict = [String: String]()

Choose a reason for hiding this comment

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

return originalDictionary.mapValues { String(describing: $0) } appears to be more concise, but it might be slower than the current implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you. I updated it with your suggestion.

return keyLowerCasedDictionary[key.lowercased()]
}
set {
var newMap = originalDictionary.filter { $0.key.caseInsensitiveCompare(key) != .orderedSame }

Choose a reason for hiding this comment

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

how about

    set {
      let lowerKey = key.lowercased()
      if let newValue = newValue {
        keyLowerCasedDictionary[lowerKey] = newValue
      } else {
        keyLowerCasedDictionary.removeValue(forKey: lowerKey)
      }
      originalDictionary = originalDictionary.filter { $0.key.lowercased() != lowerKey }
      if let newValue = newValue {
        originalDictionary[key] = newValue
      }
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me update with yours.

@dongjoon-hyun
Copy link
Member Author

Thank you for review, @LuciferYang . The updated PR looks much better to me. 😄

Copy link

@LuciferYang LuciferYang left a comment

Choose a reason for hiding this comment

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

LGTM

@dongjoon-hyun
Copy link
Member Author

Thank you again, @LuciferYang . Merged to main.

@dongjoon-hyun dongjoon-hyun deleted the SPARK-51708 branch April 3, 2025 12:10
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.

2 participants