【问题标题】:How can i reproduce this procedure to CQL (Cassandra)?如何将此过程复制到 CQL (Cassandra)?
【发布时间】:2021-06-23 02:16:49
【问题描述】:

我有这个过程,现在我需要如何将这个过程从 SQL 复制到 CQL,你能帮帮我吗? Cassandra是否与SQL中的程序相同?如果没有,我该如何为此设置变量?

CREATE PROCEDURE [dbo].[sp_DeleteOldTransactionLogs]
    @p_daysback INT
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

DECLARE 
     @r         int 
    ,@i         int
    ,@maxLogId  int
    ,@billion   int = 1000000000
    ,@deleted   int;


SET @r = 1;
SET @i = 1;
SET @deleted = 0;
 
SELECT 
    @maxLogId = MAX(ictransactionlogid)
FROM dbo.ictransactionLog WITH (INDEX(IX_ictransactionLog_time))
WHERE
    time < DATEADD(day, @p_daysback, GETDATE());

WHILE @r > 0 AND @i <= 7
BEGIN

  DELETE TOP (5000) -- this will change
    dbo.ictransactionLog
    WHERE ictransactionlogid <= @maxLogId;
 
  SET @r = @@ROWCOUNT;
  SET @deleted = @deleted + @r;

  set @i = @i + 1;
END

SELECT @maxLogId = IDENT_CURRENT( 'ictransactionLog' );

 IF @maxLogId > @billion
        BEGIN
            delete from ictransactionLog
            where ictransactionlogid < 500000000
   
            DBCC CHECKIDENT ('ictransactionLog', RESEED, 0);
        END

SELECT @deleted;
END

【问题讨论】:

  • 这太模糊了。首先尝试修改一个部分,看看你能找到什么。

标签: sql stored-procedures cassandra


【解决方案1】:

不,在 CQL 中无法做到这一点。只有用户定义的函数和用户定义的聚合是有限的,甚至它们也很有限。

您需要将其实现为某种语言的代码,例如 Python 等。

【讨论】:

    猜你喜欢
    • 2017-08-12
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    相关资源
    最近更新 更多