แชร์ผ่าน


วิธีการ: สร้างทางลัดในรายการของคุณ

บทความนี้อธิบายวิธีใช้ฟังก์ชันทางลัดในรายการปริมาณงาน Microsoft Fabric ของคุณเพื่ออ้างอิงข้อมูลจากเลคเฮาส์หรือแหล่งพื้นที่จัดเก็บข้อมูลบนคลาวด์ภายนอก เช่น Amazon S3 โดยไม่ต้องคัดลอกข้อมูล ทางลัดช่วยให้แอปพลิเคชันของคุณเข้าถึงและทํางานกับข้อมูลจากแหล่งต่างๆ ผ่านอินเทอร์เฟซแบบรวม ซึ่งรองรับ "คํามั่นสัญญาการคัดลอกครั้งเดียว" ของ OneLake

การทําความเข้าใจทางลัดใน Microsoft Fabric

ทางลัดใน Microsoft Fabric เป็นวิธีการเข้าถึงข้อมูลข้ามโดเมน ระบบคลาวด์ และบัญชีโดยการสร้างมุมมองเสมือนของข้อมูลที่อยู่ในตําแหน่งต่างๆ เมื่อคุณสร้างทางลัดในรายการปริมาณงาน คุณกําลังสร้างการอ้างอิงไปยังข้อมูลโดยไม่ต้องคัดลอกทางกายภาพ ซึ่ง:

  • ลดต้นทุนการจัดเก็บข้อมูลและความซ้ําซ้อนของข้อมูล
  • รับรองความสอดคล้องของข้อมูลโดยชี้ไปที่ข้อมูลต้นทางเสมอ
  • ลดความซับซ้อนในการเข้าถึงข้อมูลสําหรับผู้ใช้ผ่านเนมสเปซแบบรวม
  • ให้ประโยชน์ด้านประสิทธิภาพที่อาจเกิดขึ้นผ่านการแคชอัจฉริยะ

การใช้ตัวควบคุมการสร้างคําสั่งลัด

ชุดเครื่องมือการขยาย Fabric มีตัวควบคุมการสร้างทางลัดที่ช่วยลดความยุ่งยากในกระบวนการสร้างทางลัด ตัวควบคุมนี้มีส่วนติดต่อผู้ใช้ที่เป็นมาตรฐานสําหรับการสร้างทางลัด คล้ายกับประสบการณ์ในรายการ Fabric ดั้งเดิม

วิธีใช้ตัวควบคุมการสร้างคําสั่งลัดในปริมาณงานของคุณ:

  1. นําเข้าตัวควบคุมจากชุดเครื่องมือความสามารถในการขยาย:

    import { ShortcutCreationControl } from '@fabric/extensibility-toolkit';
    
  2. เพิ่มตัวควบคุมไปยังคอมโพเนนต์ของคุณ:

    <ShortcutCreationControl
      supportedSourceTypes=['Lakehouse', 'MyWorkloadName.MyItemName']}, // Specify which source types your workload supports
      supportedTargetTypes={['Lakehouse', 'MyWorkloadName.MyItemName']} // Specify which source types your workload supports
    />
    

การสร้างทางลัดโดยทางโปรแกรม

หากคุณต้องการสร้างทางลัดโดยทางโปรแกรมคุณสามารถใช้อินเทอร์เฟซ OneLakeShortcutClient ที่เรียบง่ายสําหรับการจัดการทางลัด:

การตั้งค่า OneLakeShortcutClient

import { OneLakeShortcutClient } from '../clients/OneLakeShortcutClient';
import { WorkloadClientAPI } from "@ms-fabric/workload-client";

// Initialize the client in your component or service
const shortcutClient = new OneLakeShortcutClient(workloadClient);

การสร้างทางลัดประเภทต่างๆ

ทางลัด OneLake (ผ้าเป็นผ้า):

// Create a shortcut to another Fabric item (Lakehouse, KQL Database, etc.)
const oneLakeShortcut = await shortcutClient.createOneLakeShortcut(
  workspaceId,           // Current workspace ID
  itemId,                // Current item ID
  'SharedLakehouse',     // Shortcut name
  '/Files',              // Target path in current item
  'source-workspace-id', // Source workspace ID
  'source-item-id',      // Source item ID (Lakehouse, etc.)
  '/Tables/Customers'    // Optional: specific path in source item
);

ทางลัด Amazon S3:

// Create an S3 shortcut
const s3Shortcut = await shortcutClient.createS3Shortcut(
  workspaceId,
  itemId,
  'S3CustomerData',      // Shortcut name
  '/Files',              // Target path in your item
  's3-connection-id',    // S3 connection ID (configured in Fabric)
  'my-bucket',           // S3 bucket name
  '/customer-data'       // Path within bucket
);

ทางลัด Azure Data Lake Storage Gen2:

// Create an ADLS Gen2 shortcut
const adlsShortcut = await shortcutClient.createAdlsGen2Shortcut(
  workspaceId,
  itemId,
  'ADLSData',            // Shortcut name
  '/Files',              // Target path in your item
  'adls-connection-id',  // ADLS Gen2 connection ID
  'mycontainer',         // Container name
  '/raw-data/analytics'  // Path within container
);

การจัดการคําสั่งลัดที่มีอยู่

// List all shortcuts in a folder
const shortcuts = await shortcutClient.getAllShortcuts(workspaceId, itemId, '/Files');

// Get a specific shortcut
const shortcut = await shortcutClient.getShortcut(workspaceId, itemId, '/Files/MyShortcut');

// Delete a shortcut
await shortcutClient.deleteShortcut(workspaceId, itemId, '/Files/MyShortcut');

// Filter shortcuts by type
const oneLakeShortcuts = await shortcutClient.getOneLakeShortcuts(workspaceId, itemId, '/Files');
const s3Shortcuts = await shortcutClient.getS3Shortcuts(workspaceId, itemId, '/Files');
const adlsShortcuts = await shortcutClient.getAdlsGen2Shortcuts(workspaceId, itemId, '/Files');

// Search shortcuts by name pattern
const customerShortcuts = await shortcutClient.searchShortcutsByName(
  workspaceId, itemId, '/Files', 'customer'
);

ประเภททางลัดและการกําหนดค่าแหล่งที่มา

ปริมาณงานของคุณสามารถรองรับคําสั่งลัดประเภทต่างๆ ได้ขึ้นอยู่กับกรณีการใช้งานของคุณ OneLakeShortcutClientวิธีการตัวช่วยสําหรับประเภททางลัดทั่วไป:

ทางลัด OneLake (รายการผ้า)

ทางลัด OneLake ช่วยให้ปริมาณงานของคุณเข้าถึงข้อมูลที่จัดเก็บไว้ในรายการ Fabric อื่นๆ เช่น Lakehouses, ฐานข้อมูล KQL เป็นต้น:

// Using the OneLakeShortcutClient helper method
const lakehouseShortcut = await shortcutClient.createOneLakeShortcut(
  workspaceId,
  itemId,
  "SharedLakehouse",     // Shortcut name
  "/Files",              // Target path in your item
  "source-workspace-id", // Source workspace ID
  "lakehouse-item-id",   // Source lakehouse ID
  "/Tables/myTable"      // Optional: specific path in source
);

ทางลัด Amazon S3

ทางลัด S3 ช่วยให้เข้าถึงข้อมูลที่จัดเก็บไว้ในบัคเก็ต Amazon S3:

// Using the OneLakeShortcutClient helper method
const s3Shortcut = await shortcutClient.createS3Shortcut(
  workspaceId,
  itemId,
  "CustomerDataS3",      // Shortcut name
  "/Files",              // Target path in your item
  "s3-connection-id",    // S3 connection ID (pre-configured in Fabric)
  "my-bucket",           // S3 bucket name
  "/customer-folder"     // Path within the bucket
);

การทํางานกับข้อมูลทางลัด

เมื่อสร้างทางลัดแล้ว ปริมาณงานของคุณสามารถทํางานกับข้อมูลได้โดยใช้ปุ่มOneLakeStorageClient ไคลเอ็นต์นี้มีวิธีการโต้ตอบกับทั้งเนื้อหา OneLake ปกติและข้อมูลทางลัดผ่านอินเทอร์เฟซแบบรวม

การตั้งค่า OneLakeStorageClient

import { OneLakeStorageClient } from '../clients/OneLakeStorageClient';
import { WorkloadClientAPI } from "@ms-fabric/workload-client";

// Initialize the storage client
const storageClient = new OneLakeStorageClient(workloadClient);

การทํางานกับข้อมูลเมตาของทางลัด

เมื่อทํางานกับคําสั่งลัด สิ่งสําคัญคือต้องเข้าใจว่าข้อมูลเมตาของคําสั่งลัดและเนื้อหาคําสั่งลัดจะดึงข้อมูลต่างกัน

การรับข้อมูลทางลัด

หากต้องการดูข้อมูลเกี่ยวกับคําสั่งลัดในเส้นทาง ให้ใช้ getPathMetadata กับ shortcutMetadata: true:

// Get metadata for a path including shortcut information
const metadata = await storageClient.getPathMetadata(
  workspaceId,
  'itemId/Files',       // Path to check for shortcuts
  false,                // recursive: false for current level only
  true                  // shortcutMetadata: true to include shortcut info
);

// Filter for shortcuts
const shortcuts = metadata.paths.filter(path => path.isShortcut);

console.log('Found shortcuts:', shortcuts.map(s => ({
  name: s.name,
  isShortcut: s.isShortcut,
  lastModified: s.lastModified
})));

การเข้าถึงเนื้อหาทางลัด

สําคัญ

เมื่อ shortcutMetadata: trueคุณจะได้รับเฉพาะข้อมูลเกี่ยวกับทางลัด ไม่ใช่เนื้อหาภายในทางลัด หากต้องการเข้าถึงข้อมูลจริงภายในทางลัด คุณต้องโทรแยกต่างหากโดยใช้เส้นทางของทางลัด

// First, get the shortcuts in the directory
const dirMetadata = await storageClient.getPathMetadata(
  workspaceId,
  'itemId/Files',
  false,
  true // Get shortcut metadata
);

// Find a specific shortcut
const myShortcut = dirMetadata.paths.find(path => 
  path.isShortcut && path.name === 'MyS3Shortcut'
);

if (myShortcut) {
  // Now get the content INSIDE the shortcut
  const shortcutContent = await storageClient.getPathMetadata(
    workspaceId,
    myShortcut.path,                    // Use the shortcut path
    true,                               // recursive: true to see all content
    false                              // shortcutMetadata: false to get actual content
  );

  console.log('Content inside shortcut:', shortcutContent.paths);
}

การอ่านและการเขียนข้อมูลทางลัด

เมื่อคุณมีโครงสร้างเนื้อหาทางลัดแล้ว คุณสามารถอ่านและเขียนไฟล์ได้เหมือนกับไฟล์ OneLake ทั่วไป:

// Read a file from within a shortcut
const fileContent = await storageClient.readFileAsText(
  OneLakeStorageClient.getPath(workspaceId, itemId, 'Files/MyS3Shortcut/data.csv')
);

// Write a file to a shortcut (if the shortcut supports writes)
await storageClient.writeFileAsText(
  OneLakeStorageClient.getPath(workspaceId, itemId, 'Files/MyS3Shortcut/output.txt'),
  'Processed data content'
);

การใช้ตัวห่อหุ้มรายการเพื่อการเข้าถึงที่ง่ายขึ้น

สําหรับโค้ดที่สะอาดกว่า คุณสามารถใช้ OneLakeStorageClientItemWrapper:

// Create an item wrapper for simplified access
const itemStorage = storageClient.createItemWrapper({
  workspaceId: workspaceId,
  id: itemId
});

// Get shortcuts in the Files directory
const filesMetadata = await itemStorage.getPathMetadata(
  'Files',
  false,
  true // Include shortcut metadata
);

// Access content within a shortcut
const shortcutContent = await itemStorage.getPathMetadata(
  'Files/MyShortcut',
  true,  // recursive
  false  // Get actual content, not shortcut metadata
);

// Read/write files with simpler paths
const fileContent = await itemStorage.readFileAsText('Files/MyShortcut/data.txt');
await itemStorage.writeFileAsText('Files/MyShortcut/processed.txt', 'Result data');

ตัวอย่างที่สมบูรณ์: การทํางานกับข้อมูลทางลัด

async function analyzeShortcutData(workspaceId: string, itemId: string) {
  const storageClient = new OneLakeStorageClient(workloadClient);
  
  try {
    // Step 1: Find all shortcuts in the Files directory
    const dirMetadata = await storageClient.getPathMetadata(
      workspaceId,
      `${itemId}/Files`,
      false,
      true // Get shortcut info
    );

    const shortcuts = dirMetadata.paths.filter(path => path.isShortcut);
    console.log(`Found ${shortcuts.length} shortcuts`);

    // Step 2: For each shortcut, analyze its content
    for (const shortcut of shortcuts) {
      console.log(`\nAnalyzing shortcut: ${shortcut.name}`);
      
      // Get the content inside this shortcut
      const shortcutContent = await storageClient.getPathMetadata(
        workspaceId,
        `${itemId}/Files/${shortcut.name}`,
        true,  // recursive to see all files
        false  // get actual content, not shortcut metadata
      );

      console.log(`  - Contains ${shortcutContent.paths.length} items`);
      
      // List all files in the shortcut
      const files = shortcutContent.paths.filter(p => !p.isDirectory);
      for (const file of files) {
        console.log(`  - File: ${file.name} (${file.contentLength} bytes)`);
        
        // Optionally read the file content
        if (file.name.endsWith('.txt') || file.name.endsWith('.csv')) {
          try {
            const content = await storageClient.readFileAsText(
              OneLakeStorageClient.getPath(workspaceId, itemId, `Files/${shortcut.name}/${file.name}`)
            );
            console.log(`    Preview: ${content.substring(0, 100)}...`);
          } catch (error) {
            console.log(`    Could not read file: ${error.message}`);
          }
        }
      }
    }
  } catch (error) {
    console.error('Error analyzing shortcut data:', error);
  }
}

ข้อควรพิจารณาด้านความปลอดภัย

ทางลัดเคารพบริบทความปลอดภัยของผู้ใช้:

  • สําหรับแหล่งข้อมูลภายในของ Fabric (เช่น Lakehouses) ระบบจะใช้ข้อมูลประจําตัวของผู้ใช้ที่โทร
  • สําหรับแหล่งข้อมูลภายนอก (เช่น S3) จะใช้ข้อมูลรับรองการเชื่อมต่อที่ระบุระหว่างการสร้างทางลัด

ตรวจสอบให้แน่ใจว่าปริมาณงานของคุณจัดการการรับรองความถูกต้องอย่างถูกต้อง และจัดเตรียมองค์ประกอบอินเทอร์เฟซผู้ใช้ที่เหมาะสมสําหรับการป้อนรายละเอียดการเชื่อมต่ออย่างปลอดภัย