首页 > 其他分享 >How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes

时间:2024-09-14 16:54:04浏览次数:14  
标签:Function function 20 Built AI Cursor TiDB files string

作者: ngaut

In this tutorial, we’ll walk you through the steps to add a flexible built-in function to TiDB that leverages LLM to process data. We’ll use the AI_PROCESS function as an example, which takes two parameters: a data string and a task_description string, returning a processed result.### Why Use a Cursor to Add Built-in Functions?****By using a tool like Cursor, developers can interact with the codebase of TiDB in an intuitive way, shortening development time. Cursor helps identify the necessary files to modify and can even suggest potential missing files. For this tutorial, we’ll rely on Cursor to streamline the process.### **Step 1: Launch CursorStart by launching the Cursor tool. Cursor will allow you to browse through the TiDB source code directory seamlessly.**1. Open the TiDB Source Code: Use the cursor to open any file within the project directory. 2. MacOS Users: Hit “Command + L” to open the chatting window for further interactions with Cursor.### **Step 2: Define the Function SignatureNext, define the function signature of the built-in function you want to add. In this case, it’s:**func AI_PROCESS(data string, task_description string) string\



Step 3: Use Cursor to Locate the Files****You can ask Cursor to search through the codebase for the files where you need to make modifications. Start by inputting the following command in the Cursor chat window(I missed some files, but surprisingly cursor figured it out):****I want to add a built-in function to TiDB. The signature is: AI_PROCESS(data string task_description string). Locate all the files I need to change or add. Start with @parser.y, @builtin_other.go, @builtin.go, and @builtin_vectorized.go.

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_https

Cursor will identify all the required files, even if you miss a few. This is one of Cursor’s strengths—its ability to catch overlooked details.

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_https_02

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_server_03

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_server_04

### Step 4: Implement the Stub Function****Once you have located the relevant files, the next step is to implement a stub function for AI_PROCESS. Again, Cursor can help you automatically fill in the necessary implementation.

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_type_05

Later, I asked the cursor to change the function a little bit to remove the json constraint.### Step 5: Testing the Function****Finally, type “make server” to build tidb-server, run it, and enjoy your new AI_PROCESS function in your local TiDB instance to ensure it works as expected.

How to Add a Built-in Function to TiDB Using a Cursor in 20 Minutes_blog_06

\



Conclusion****Adding a built-in function to TiDB using Cursor can save you a significant amount of time by automating the file search process and providing helpful suggestions. In just 20 minutes, you can integrate an AI-powered function that enhances the flexibility of TiDB. Happy coding!

标签:Function,function,20,Built,AI,Cursor,TiDB,files,string
From: https://blog.51cto.com/tidb/12017930

相关文章

  • 拓数派荣登2024年《财富》中国最具社会影响力的创业公司
    9月11日,全球著名商业杂志《财富》(FortuneMagazine)在其中文版发布“2024年中国最具社会影响力的创业公司”榜单。拓数派凭借基础AI理论、产品在核心领域应用,AI向善品牌影响力等方面的综合竞争力荣誉上榜。作为《财富》最具权威性的榜单之一,“中国最具社会影响力的创业公司”榜单聚......
  • 合宙Air201模组LuatOS:点灯仪式
    上一期教程,我们学习了合宙Air201helloworld,很多小伙伴有了初步了解,接下来,推出第二篇:你将体验工程师的重要仪式——点灯!Air201点灯教程  合宙Air201资产定位模组——是一个集成超低功耗4G通信、语音通话、超低功耗定位、计步、震动、Type-C、充电、放音、录音等功能的超小PCBA。......
  • 合宙Air201模组LuatOS:远程控制
    很多小伙伴已经学习了前两期教程helloworld、点灯,对合宙Air201这款低功耗资产定位模组的LuatOS开发已有一定了解,大家的实操反馈是:真的很简单!那么,这一期我们要一起体验更有趣的——远程控制点灯!Air201远程控制点灯教程  合宙Air201资产定位模组——是一个集成超低功耗4G通信、语......
  • 美团笔试2024秋1
    1、图染色法在编译原理中,寄存器分配是代码优化阶段的一项重要任务。寄存器分配的目标是为了有效地将程序中的活跃变量映射到有限数量的处理器寄存器上。在这个过程中,图染色法是一种常用的技术,它通过构建一个冲突图(其中节点代表活跃变量,边代表不能同时分配到同一寄存器的变量对......
  • 图纸加密软件哪个最好用?七款顶级图纸加密软件大比拼! (2024年图纸设计行业必备)
    在图纸行业,每一份设计图纸都承载着企业的核心竞争力与智慧结晶。图纸一旦泄露,不仅可能导致知识产权的丧失,还可能影响企业的市场竞争力和品牌形象。因此,选择一款高效、可靠的图纸加密软件,对于图纸行业的企业而言,无疑是保护核心资产、确保业务连续性的必备之选。接下来,我们将......
  • 2024.9.13(周五)
    完成机器学习查询数据集的作业数据集名称样本数属性属性个数标签任务Iris数据集150花萼长度,花萼宽度,花瓣长度,花瓣宽度4鸟类(Setosa,Versicolor,Virginica)分类MNIST数据集70,000像素值(28x28像素)784手写数字(0-9)分类Titanic数据集891乘客ID,船舱......
  • 2024年06月中国电子学会青少年软件编程(图形化)等级考试试卷(四级)答案 + 解析
    青少年软件编程(图形化)等级考试试卷(四级)分数:100题数:24一、单选题(共10题,共30分)1.运行下列程序,输入单词“PLAY”,最后角色说?()A.LY4APB.AP4LYC.YA4PLD.PL4AY正确答案:B答案解析:根据程序分析可知,首先获取单词字符数,然后奇数位的字母放在字符数左侧,......
  • 2024年06月中国电子学会青少年软件编程(图形化)等级考试试卷(一级)答案 + 解析
    青少年软件编程(图形化)等级考试试卷(一级)分数:100题数:37一、单选题音乐VideoGame1的时长将近8秒,点击一次角色,下列哪个程序不能完整地播放音乐两次?()A.B.C.D.正确答案:D答案解析:D选项只会播放一遍声音水果盲盒角色有6个造型,其中星星造型表示神秘大礼......
  • 2024年06月中国电子学会青少年软件编程(Python)等级考试试卷(一级)答案 + 解析
    青少年软件编程(Python)等级考试试卷(一级)分数:100 题数:37一、单选题(共25题,共50分)1.在使用turtle绘制图形时,如果要控制小海龟移动到x坐标为200,y坐标为150的位置,以下代码能够实现效果的是?()A.turtle.go(150,200)B.turtle.go(200,150)C.turtle.goto(150,200)D.......
  • P4568 [JLOI2011] 飞行路线
    P4568[JLOI2011]飞行路线考虑跑多层图,每层图连条边权为0的边,跑dijkstra即可。#include<bits/stdc++.h>usingnamespacestd;#definelllonglongconstintN=1e7+10;intn,m,k,s,t;intcnt;inthead[N];structss{ intto,w,next;}a[N];voidadd(intu,int......