Mock API Query Functionality (dataservice-query & data-service-portal)
dataservice-query
Diagram: request handling from controller to handler.
sequenceDiagram
participant Client as Portal/Tooling
participant Controller as MockDataPreviewController
participant Service as QueryServiceImpl
participant Handler as MockQueryHandler
participant Utils as FakeDataUtils
Client->>Controller: POST /mock/data/preview (limit, columns, rules)
Controller->>Service: previewData(request)
alt Query status == MOCKING
Service->>Service: mockQueryHandle(request)
Service->>Handler: previewMockData(...)
Handler->>Utils: generateMockData(column rule)
Utils-->>Handler: synthetic row values
Handler-->>Service: PreviewResponse(page rows, meta)
else Other statuses
Service->>Service: Delegate to regular query path
end
Service-->>Controller: ResponseDTO(rows, stats)
Controller-->>Client: HTTP 200 Preview payload
MockDataPreviewController exposes POST /mock/data/preview, validating pagination params and delegating to MockQueryHandler.previewData for paged preview responses (dataservice-query/src/main/java/com/shopee/data/dataservice/query/controller/MockDataPreviewController.java:16).
QueryServiceImpl.handle routes API requests whose status is MOCKING into mockQueryHandle, which synthesises preview payloads, OLAP shards, or gzip/encrypted job artifacts on demand (dataservice-query/src/main/java/com/shopee/data/dataservice/query/service/impl/QueryServiceImpl.java:107, dataservice-query/src/main/java/com/shopee/data/dataservice/query/service/impl/QueryServiceImpl.java:607).
MockQueryHandler materialises schemas and rows in-memory: its preview/OLAP/HBase helpers loop through requested rows and call generateMockData, fanning out to FakeDataUtils for random/date/array cases and recycling AI seed lists via modulo indexing (dataservice-query/src/main/java/com/shopee/data/dataservice/query/service/MockQueryHandler.java:217, :333, :407).
Generated results are never persisted; every invocation recomputes rows, with optional AES encryption + GZIP wrapping performed just before returning to clients (dataservice-query/src/main/java/com/shopee/data/dataservice/query/service/MockQueryHandler.java:95).
DTO validation caps preview volume (≤500 rows) and enforces per-column datatype/mock-type compatibility before generation starts (dataservice-query/src/main/java/com/shopee/data/dataservice/query/dto/MockPreviewRequest.java:11, dataservice-query/src/main/java/com/shopee/data/dataservice/query/dto/ColumnDTO.java:26).
Regression coverage in FakeDataUtilsTest locks down low-level generators across negative ranges, identical bounds, and high precision scenarios (dataservice-query/src/test/java/com/shopee/data/dataservice/query/FakeDataUtilsTest.java:336).
Commit Highlights (origin/dev-mock-query)
41c33ca3 (mengyang.chen, 2025-10-20): initial pipeline, new handler + service wiring for MOCKING APIs.
Diagram: portal orchestration around the query service.
flowchart TD
A[UI User requests mock preview] --> B[MockController]
B --> C[MockServiceImpl.previewMockData]
C --> D[MockPreviewRequest.validate]
C --> E[Strip AI seeds from payload]
C --> F[QueryServiceFeignClient.previewMockData]
F --> G[dataservice-query MockPreview]
G --> F
C --> H[fillAIMockData via Smart agent]
H --> C
C --> I[Assemble Portal DTO response]
I --> J[Return to UI]
MockController surfaces /mock/preview and /mock/type/list to the UI, piping requests into MockService (data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/controller/MockController.java:30).
MockPreviewRequest mirrors the query-service DTO, validating ≤500 rows and at least one column while providing helpers to clone the payload for the downstream call (data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/dto/mock/MockPreviewRequest.java:15).
MockServiceImpl.previewMockData orchestrates the flow:
Validates columns locally and strips existing AI mockData so the query service receives only rules (data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/service/impl/MockServiceImpl.java:49).
Invokes dataservice-query via QueryServiceFeignClient.previewMockData and converts the response into column-centric DTOs (data-service-portal/dependencies/src/main/java/com/shopee/data/dataservice/dependencies/query/QueryServiceFeignClient.java:91, data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/service/impl/MockServiceImpl.java:81).
Calls fillAIMockData to backfill AI-generated columns through the Smart agent if the query service returned empty seeds; portalside AI results are cached only in-memory per request (data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/service/impl/MockServiceImpl.java:99).
MockCol.check enforces datatype/mock-type compatibility, array length rules, random-number bounds, AI prompt presence, etc., throwing detailed validation errors before any remote calls occur (data-service-portal/dependencies/src/main/java/com/shopee/data/dataservice/dependencies/query/entity/mock/MockCol.java:22).
AIAgentServiceImpl.smartAgentMockData delegates to the Smart platform, parsing responses into a simple column→values map without persisting results; values are trimmed to CommonConstants.MAX_MOCK_DATA_ROWS for UI display (data-service-portal/api/src/main/java/com/shopee/data/dataservice/external/service/impl/AIAgentServiceImpl.java:44, data-service-portal/api/src/main/java/com/shopee/data/dataservice/external/dto/MockDataResp.java:17).
Errors from AI parsing raise CommonRuntimeExceptionEnum.MOCK_PARSE_FAILED, giving the UI a consistent 500-series response (data-service-portal/common/src/main/java/com/shopee/data/dataservice/common/exception/CommonRuntimeExceptionEnum.java:69).
Commit Highlights (origin/feat-1.13.2-mockapi)
b7434bc1d (Wang Jingying, 2025-10-03): initial mock feature scaffolding—controller endpoints, service wiring, Smart agent integration, DTOs, and configuration.
37a5f0691 (Wang Jingying, 2025-10-21): refactored preview flow into new MockCol/IMockCol abstractions shared with the query dependency module, reducing duplication.
dade105bc / a501c2c53 (Wang Jingying, 2025-10-23): polished error messaging and datatype naming ahead of merge back to dev (via feat-1.13.2-mockapi).
How Mock Data Is Managed End-to-End
Diagram: lifecycle of mock data per request.
stateDiagram-v2
[*] --> PortalValidation: Portal validation & AI seed prep
PortalValidation --> QueryGeneration: Call dataservice-query for mock rows
QueryGeneration --> EncryptionCheck: Optional AES + GZIP wrapping
EncryptionCheck --> ResponseAssembly: Query response returned to portal
ResponseAssembly --> PortalAIMerge: Portal merges AI seeds if query empty
PortalAIMerge --> [*]: Final preview delivered to UI
Every preview request results in fresh, in-memory generation. The portal validates and hydrates AI seeds, while the query service materialises row payloads; no database or cache stores results between requests.
AI-generated columns receive values twice: the portal optionally seeds them via Smart agent, and the query service cycles any provided seed lists to populate row arrays. If the query layer returns empty data, the portal swaps in the freshly generated AI results before responding to the client (data-service-portal/api/src/main/java/com/shopee/data/dataservice/api/service/impl/MockServiceImpl.java:60).
Both services guard against invalid inputs early (validation annotations + explicit assertions), ensuring malformed mock rules fail fast before any remote execution.