定制 vasatiani/laravel-athena 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vasatiani/laravel-athena

Composer 安装命令:

composer require vasatiani/laravel-athena

包简介

Laravel Athena query builder integration with Eloquent support and Redis-safe concurrency.

README 文档

README

A modern, clean, and scalable integration of AWS Athena with Laravel's Query Builder and Eloquent ORM.
Built with full support for Laravel 10–12, Redis-based concurrency limits, Octane/Swoole compatibility, and Athena-specific query and schema grammar.

🚀 Features

  • ✅ Eloquent & Query Builder support
  • ✅ Safe concurrency control (Athena allows max 20 concurrent queries)
  • ✅ S3 query result management
  • ✅ Redis lock support (Octane/Swoole-friendly)
  • ✅ Schema-aware DDL generation (CREATE TABLE)
  • ✅ Custom grammar for BETWEENLIMIT, Athena-safe LIMIT/OFFSET
  • ✅ Fully configurable via config/athena.php

📦 Installation

composer require vasatiani/laravel-athena

Then publish the config file:

php artisan vendor:publish --tag=config

🛠 Configuration

Located in config/athena.php

return [
    'credentials' => [
        'key'    => env('AWS_KEY', ''),
        'secret' => env('AWS_SECRET', ''),
    ],
    'region'        => env('AWS_REGION', 'eu-central-1'),
    'version'       => 'latest',
    'database'      => env('ATHENA_DB', ''),
    'prefix'        => env('ATHENA_TABLE_PREFIX', ''),
    'bucket'        => env('S3_BUCKET', ''),
    'outputfolder'  => env('ATHENA_OUTPUT_FOLDER', 'athena-output'),

    's3output'      => 's3://' . env('S3_BUCKET', '') . '/' . env('ATHENA_OUTPUT_FOLDER', 'athena-output'),

    // Concurrency control
    'lock_key'      => env('ATHENA_LOCK_KEY', 'athena:query:concurrency'),
    'lock_timeout'  => env('ATHENA_LOCK_TIMEOUT', 10),
    'lock_wait'     => env('ATHENA_LOCK_WAIT', 5),

    // Schema creation options
    'stored_as' => 'PARQUET',
    'table_properties' => [
        'has_encrypted_data' => 'false',
        'classification'     => 'json',
    ],
];

Make sure your .env contains:

AWS_KEY=your-key
AWS_SECRET=your-secret
AWS_REGION=eu-central-1
S3_BUCKET=your-bucket
ATHENA_DB=your_database
ATHENA_OUTPUT_FOLDER=athena-output

🧩 Usage

🏗 Defining a Model

namespace App\Models;

use Vasatiani\Athena\Model;

class AthenaEvent extends Model
{
    protected $table = 'events';
}

📋 Running Queries

use App\Models\AthenaEvent;

$events = AthenaEvent::where('event_type', 'login')->get();

$events = AthenaEvent::query()
    ->whereDateBetween('created_at', '2024-01-01', '2024-01-31')
    ->get();

$events = AthenaEvent::whereRegex('event_name', '^checkout_.*')->get();

🔐 Automatic Query Caching

Queries are hashed and stored in the athena_query_hashes table.

If the table is missing, the system will fallback gracefully.

Migration:

Schema::create('athena_query_hashes', function (Blueprint $table) {
    $table->string('query_hash')->primary();
    $table->string('aws_return_id');
    $table->timestamps();
});

💥 Custom Query Builder Helpers

AthenaEvent::whereNotEmpty('email')->get();
AthenaEvent::selectIfEmpty(['id', 'name'])->get();
AthenaEvent::whereJsonHasKey('payload', 'device_id')->get();

🧱 Schema Support (Optional)

Schema::connection('athena')->create('events', function (Blueprint $table) {
    $table->string('event_type');
    $table->timestamp('created_at');
});

This generates:

CREATE EXTERNAL TABLE events (
  event_type string,
  created_at timestamp
)
STORED AS PARQUET
LOCATION 's3://your-bucket/athena-output'
TBLPROPERTIES ('has_encrypted_data'='false','classification'='json')

⚠️ Athena LIMIT & OFFSET Handling

Internally converted to ROW_NUMBER() queries via special syntax BETWEENLIMIT.

✅ Redis Lock Integration

Uses Laravel's Cache::lock() to prevent exceeding Athena’s concurrency limits.

🧪 Testing

DB::connection('athena')->select("SELECT count(*) as total FROM users");

📘 License

MIT © Vakho Asatiani

vasatiani/laravel-athena 适用场景与选型建议

vasatiani/laravel-athena 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 vasatiani/laravel-athena 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vasatiani/laravel-athena 我们能提供哪些服务?
定制开发 / 二次开发

基于 vasatiani/laravel-athena 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 37
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-30