शुरू करेंमुफ़्त में शुरू करें

नेस्टेड डेटा मर्ज करना

HR टीम कर्मचारियों का डेटा दो अलग-अलग JSON फ़ाइलों में रखती है: एक में बेसिक जानकारी और दूसरी में अतिरिक्त attributes. एक पूरा employee profile बनाने के लिए, आपको एक सामान्य पहचानकर्ता से इन टेबल्स को जॉइन करना है.

Inner join उन पंक्तियों को मिलाता है जिनमें join कॉलम मैच करता है — जैसे दो गेस्ट लिस्ट को नाम से मर्ज करना. JsonReader, JsonReadOptions, और Table क्लास आपके लिए इम्पोर्ट कर दी गई हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Java में डेटा इम्पोर्ट करना

पाठ्यक्रम देखें

अभ्यास निर्देश

  • पहली JSON फ़ाइल के लिए टेबल का नाम सेट करें.
  • दूसरी फ़ाइल के लिए builder chain पूरी करें.
  • टेबल्स को "id" कॉलम पर जॉइन करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

public class NestedEmployees {
    public static void main(String[] args) {

        // Set table name for first JSON
        JsonReadOptions opts1 = JsonReadOptions
                .builder("employees.json")
                .____("Main")
                .build();
        Table main = new JsonReader().read(opts1);

        // Complete builder chain for second JSON
        JsonReadOptions opts2 = JsonReadOptions
                .builder("employees_extra.json")
                .tableName("Extra")
                .____();
        Table extra = new JsonReader().read(opts2);

        System.out.println("Main columns: " + main.columnNames());
        System.out.println("Extra columns: " + extra.columnNames());

        // Join tables on id column
        Table joined = main.____("id").____(extra);

        System.out.println("\nJoined table (inner join on id):");
        System.out.println(joined.print());
    }
}
कोड संपादित करें और चलाएँ