玩心态

文章 评论 浏览 30

玩心态 2025-02-04 11:08:39

警告:非法字符串偏移'xxx'

这会在您尝试使用Square Bracket语法访问数组元素时会发生这种情况,但是您正在在字符串上而不是在数组上进行此操作,因此该操作明确没有有意义

示例:

$var = "test";
echo $var["a_key"];

如果您认为该变量应该是一个数组,请查看其来自何处并在那里解决问题。

Warning: Illegal string offset 'XXX'

This happens when you try to access an array element with the square bracket syntax, but you're doing this on a string, and not on an array, so the operation clearly doesn't make sense.

Example:

$var = "test";
echo $var["a_key"];

If you think the variable should be an array, see where it comes from and fix the problem there.

参考 - 此错误在PHP中意味着什么?

玩心态 2025-02-04 07:16:40

如果删除 sort_asc ,则您的代码工作正常。这是因为PHP将按预期对您的子阵列进行排序。它将从子阵列的开头进行比较。 demo

array_multisort(array_column($array, 'earnest_money_due'), $array);

( 很好。 ( demo

array_multisort(array_map(fn($row) => $row['earnest_money_due']['value'], $array), $array);

使用 usort()也没有错。 ( demo

usort($array, fn($a, $b) => $a['earnest_money_due']['value'] <=> $b['earnest_money_due']['value']);

无论您使用哪种 array_multsort()您不使用的技术,需要明确使用 sort_asc ,因为这是默认排序顺序。

If you remove the SORT_ASC, then your code works just fine. This is because PHP will sort your subarray as expected with it removed. It will compare from the start of the subarray. (Demo)

array_multisort(array_column($array, 'earnest_money_due'), $array);

If that seems too hacky, unreliable, or unintuitive, array_map() is fine. (Demo)

array_multisort(array_map(fn($row) => $row['earnest_money_due']['value'], $array), $array);

There is also nothing wrong with using usort(). (Demo)

usort($array, fn($a, $b) => $a['earnest_money_due']['value'] <=> $b['earnest_money_due']['value']);

Regardless of which array_multsort() technique you use, you don't need to explicitly use SORT_ASC because this is the default sorting order.

在列中按列值对多维数组进行排序

玩心态 2025-02-03 16:58:26

您正在使用的Bootstrap的版本显然不支持通过自定义变量来自定义。至少用于定制按钮颜色。尝试使用v。5.2目前是Beta:

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />

<style>
.btn-primary {
  --bs-btn-bg: tomato;
  --bs-btn-border-color: tomato;
}
</style>

<button class="btn btn-primary">
 I like tomato!
</button>

The version of Bootstrap you are using apparently doesn't support customization via custom variables. At least for customization of button colors. Try using v. 5.2 which is beta for now:
https://getbootstrap.com/docs/5.2/getting-started/introduction/

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous" />

<style>
.btn-primary {
  --bs-btn-bg: tomato;
  --bs-btn-border-color: tomato;
}
</style>

<button class="btn btn-primary">
 I like tomato!
</button>

如何使用以下方式设置Bootstrap 5&#x27的CSS变量?

玩心态 2025-02-02 18:34:04

只是猜测而没有看到任何实际数据...

Sub TestTemp_Cal()
    
    Dim ws As Worksheet, c As range, rng As range

    Set ws = Activesheet
    Set c = ws.Cells(Rows.Count, "J").End(xlUp)

    If c.Row > 44 Then 'make sure you can offset at least 39 rows
        Set rng = c.Offset(-39).Resize(12) '39 rows up and resize to 12 rows
        ws.Range("J3").Formula = "=ROUND(AVERAGE(" & rng.address(False, False) & "),0)"
    End If
    
End Sub

Just guessing without seeing any actual data...

Sub TestTemp_Cal()
    
    Dim ws As Worksheet, c As range, rng As range

    Set ws = Activesheet
    Set c = ws.Cells(Rows.Count, "J").End(xlUp)

    If c.Row > 44 Then 'make sure you can offset at least 39 rows
        Set rng = c.Offset(-39).Resize(12) '39 rows up and resize to 12 rows
        ws.Range("J3").Formula = "=ROUND(AVERAGE(" & rng.address(False, False) & "),0)"
    End If
    
End Sub

试图计算带有VBA的范围的最后12小时内的1小时范围

玩心态 2025-02-02 09:44:37

默认情况下,Mongorestore重建了索引,如果您想出于某种原因仅还原数据,则可以添加以下选项:

 --noIndexRestore

防止Mongorestore恢复和构建相应的Mongodump输出中指定的索引。

By default mongorestore rebuild the indexes , if you want by some reason to restore only the data you may add the following option:

 --noIndexRestore

That prevents mongorestore from restoring and building indexes as specified in the corresponding mongodump output.

official monogDB docs

为什么蒙古斯托尔还原索引?

玩心态 2025-02-01 23:45:05

很简单。您使用了错误的列名, values_old 而不是 value_old

但是您的公式将无法正常工作,然后因为这些都无法正常工作:

text.lower([value_old]) =“ n/a”或text.lower([value_old])=“ na”

,因为您正在比较刚刚转换为较低案例与上案例的东西

,因此您可能想要以下,其中包括 try 您似乎已经排除了代码

= Table.AddColumn(#"Changed Type", "Custom", each try Number.From([Value_old]) otherwise if Text.Contains([Value_old],"not required",Comparer.OrdinalIgnoreCase) or Text.Lower([Value_old]) = "n/a" or Text.Lower([Value_old]) ="na" or [Value_old] = "100" or [Value_old] = 100 then 2 else [Value_old])

It's simple. you used the wrong column name, Values_old instead of Value_old

But your formula won't work then either since neither of these will ever work:

Text.Lower([Value_old]) = "N/A" or Text.Lower([Value_old]) ="NA"

because you are comparing something you just converted to lower case against an upper case

so you probably want below, which includes the try part you seem to have left out of your code

= Table.AddColumn(#"Changed Type", "Custom", each try Number.From([Value_old]) otherwise if Text.Contains([Value_old],"not required",Comparer.OrdinalIgnoreCase) or Text.Lower([Value_old]) = "n/a" or Text.Lower([Value_old]) ="na" or [Value_old] = "100" or [Value_old] = 100 then 2 else [Value_old])

电源查询自定义列带数字和文本

玩心态 2025-02-01 13:41:21

出色地。 “班级”到底是什么意思?还是换句话说,为什么我们需要班级操作员过载?

当我们超载运算符时,我们定义如何操作属于同一类的数据。我们如何比较它们?让我们声明并实施一个超载的操作员'&lt;'为了解决这个问题。

class Stone
{
public:
    bool operator<(const Stone& anotherStone)
    {
        return this->_weight < anotherStone._weight;
    }

    float _weight;
}

您会发现,可以比较石头的类。相似性,我们通过声明和实现'='运算符来定义同一类事物的分配。

class Stone
{
public:
    bool operator<(const Stone& anotherStone)
    {
        return this->_weight < anotherStone._weight;
    }

    void operator=(const Strong& anotherStone)
    {
        this->_weight = anotherStone._weight;
    }

    float _weight;
}

总之,我们过载运算符仅用于操纵同一类中的数据,这就是操作员过载的用法。

对于您的代码,C1属于类容器,C2属于类容器,它们是完全不同的类。定义“模板复制构造函数”是没有意义的。

但是,汇编没有抱怨,因为“ int”和“ float”类型可以隐式转换。如果变量C2是容器的类型,那么您将不会像这样幸运。

Well. What exactly does "class" mean? Or in other words, why we need operator overloading for a class?

When we overload an operator, we define how to operate data belonging to the same class. How do we compare them? Let's declare and implement an overloaded operator '<' for it to solve this problem.

class Stone
{
public:
    bool operator<(const Stone& anotherStone)
    {
        return this->_weight < anotherStone._weight;
    }

    float _weight;
}

You see, the class of stone can then be compared. Similarity, we define the assignment of the same class of things by declaring and implementing '=' operator.

class Stone
{
public:
    bool operator<(const Stone& anotherStone)
    {
        return this->_weight < anotherStone._weight;
    }

    void operator=(const Strong& anotherStone)
    {
        this->_weight = anotherStone._weight;
    }

    float _weight;
}

In conclusion, we overload operators just for manipulating data within the same class, and that's the usage of operator overloading.

For your code, c1 belongs to class Container and c2 belongs to class Container, they are totally different classes. It makes no sense to define a 'template copy constructor'.

But the compilation complains nothing just because the type 'int' and type 'float' could be converted one another implicitly. If the variable c2 is the type of Container, you will not be lucky like this.

为什么模板类分配操作员可以使用“模板复制构造函数”分配不同的类型

玩心态 2025-02-01 11:25:23

RTMP是基于TCP的协议,标准入口不支持TCP服务。

Nginx Ingress Controller(看起来您正在使用)可以被配置为公开TCP服务

首先,您需要确保在 stream> stream-server-srv 服务中同时公开HTTP和RTMP端口:(

apiVersion: v1
kind: Service
metadata:
  name: stream-server-srv
  namespace: default
spec:
  selector:
    app: stream-server
  type: ClusterIP
  ports:
    - name: http-port
      port: 8000
      targetPort: 8000
      protocol: TCP
    - name: rtmp-port
      port: 1935
      targetPort: 1935
      protocol: TCP

用命名空间替换默认值)

您还需要确保也暴露了1935年端口。例如:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.2.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  - name: rtmp
    port: 1935
    protocol: TCP
    targetPort: 1935
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

最后,您需要更新/修补nginx TCP服务配置:(

kubectl patch configmap tcp-services -n ingress-nginx --patch '{"data":{"1935":"default/stream-server-srv:1935"}}'

用命名空间/serviceName替换“默认/stream-server-srv”)

RTMP is a TCP-based protocol and standard Ingress does not support TCP services.

The NGINX Ingress controller (which it looks like you are using) can be configured to expose TCP services.

First, you'll need to make sure that you expose both the HTTP and RTMP ports in your stream-server-srv Service:

apiVersion: v1
kind: Service
metadata:
  name: stream-server-srv
  namespace: default
spec:
  selector:
    app: stream-server
  type: ClusterIP
  ports:
    - name: http-port
      port: 8000
      targetPort: 8000
      protocol: TCP
    - name: rtmp-port
      port: 1935
      targetPort: 1935
      protocol: TCP

(replace default with your namespace)

You will also need to make sure that the Service used to expose the NGINX ingress exposes port 1935 as well. For example:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.2.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  externalTrafficPolicy: Local
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  - name: rtmp
    port: 1935
    protocol: TCP
    targetPort: 1935
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: LoadBalancer

Finally, you'll need to update / patch the NGINX tcp services ConfigMap:

kubectl patch configmap tcp-services -n ingress-nginx --patch '{"data":{"1935":"default/stream-server-srv:1935"}}'

(replace "default/stream-server-srv" with your namespace/servicename)

如何在Ingress Nginx中设置RTMP协议?

玩心态 2025-02-01 08:57:23

您缺少检查空输入的支票。在您的测试中,您将一个空列表传递给 deleteusers 在此SQL语句中导致:

delete from user wher;

我希望DBMS将其拒绝为无效的SQL,但也许有人将其解释为>从用户中删除,该>仅删除所有用户。 (正如@stevebosman所指出的那样, wher 被解释为表格别名 - 由于丢失的最后一个 e - 没有保留的单词Anymoere)

基本上您有2个选项。要么通过传递空列表来删除所有用户是有效的用例 - 在这种情况下,您应该通过产生适当的SQL来正确处理它。否则,如果 IDS 为空,则应该调整代码以引发异常。

@Override
public boolean deleteUsers(List<String> ids) throws Exception {
  if (ids == null || ids.size() == 0) {
    throw new IllegalArgumentException("List of IDs must not be empty");
  }
  
  ...
}

当然,您可以返回 false 在空输入的情况下,以表明没有删除用户。

要将值传递到测试中的 deleteusers 方法,您需要将值添加到使用的列表:

userDAOImpl.addUser("admin3", "111222");
final List<String> idsToDelete = new ArrayList<>();
idsToDelete.add("111222");
userDAOImpl.deleteUsers(idsToDelete);

You're missing a check for empty input. In your test you pass an empty list to deleteUsers which results in this SQL statement:

delete from user wher;

I'd expect that the DBMS would reject this as invalid SQL but perhaps there are some where this is interpreted as delete from user which simply deletes all users. (As @SteveBosman pointed out the wher is interpreted as table alias as it is - due to the missing last e - no reserved word anymoere)

Basically you have 2 options. Either deleting all users by passing an empty list is a valid use case - in which case you should handle it properly by producing proper SQL. Or this is not expected and you should adapt your code to throw an Exception if ids is empty.

@Override
public boolean deleteUsers(List<String> ids) throws Exception {
  if (ids == null || ids.size() == 0) {
    throw new IllegalArgumentException("List of IDs must not be empty");
  }
  
  ...
}

You could of course return false in case of an empty input as well to indicate no users were deleted.

To pass values to the deleteUsers method in your test you need to add values to the used list:

userDAOImpl.addUser("admin3", "111222");
final List<String> idsToDelete = new ArrayList<>();
idsToDelete.add("111222");
userDAOImpl.deleteUsers(idsToDelete);

如何在我的列表中找到所选ID&lt; string&gt; IDS arraylist?

玩心态 2025-02-01 07:30:05

通常的操作否定了所有动画和用户输入。如文档中所述:

取消任何活动动画。如果用户当前滚动,则该操作被取消。

为了归档您要做的事情,您可以使用以下类扩展名:

class SmoothPageController extends PageController {
  SmoothPageController({
    int initialPage = 0,
    bool keepPage = true,
    double viewportFraction = 1.0,
  }) : super(
          initialPage: initialPage,
          keepPage: keepPage,
          viewportFraction: viewportFraction,
        );

  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}

现在您可以调用 SmoothJumpto()就像 jumpto(),但无需解雇活动动画,例如用户输入。

final SmoothPageController pageController = SmoothPageController(initialPage: 0);

The usual operations dismiss all animation and user inputs. As also described in the documentation:

Any active animation is canceled. If the user is currently scrolling, that action is canceled.

In order to archive what you are trying to do you can use the following class extension:

class SmoothPageController extends PageController {
  SmoothPageController({
    int initialPage = 0,
    bool keepPage = true,
    double viewportFraction = 1.0,
  }) : super(
          initialPage: initialPage,
          keepPage: keepPage,
          viewportFraction: viewportFraction,
        );

  /// Jumps the scroll position from its current value to the given value,
  /// without animation, and without checking if the new value is in range.
  /// Any active animation is being kept. If the user is currently scrolling,
  /// that action is kept and will proceed as expected.
  /// Copied from ScrollController.
  void smoothJumpTo(double value) {
    assert(positions.isNotEmpty,
        'ScrollController not attached to any scroll views.');
    for (final ScrollPosition position in List<ScrollPosition>.of(positions)) {
      position.correctPixels(value);
    }
  }
}

Now you can call smoothJumpTo() just like jumpTo() but without dismissing active animations, such as the user input.

final SmoothPageController pageController = SmoothPageController(initialPage: 0);

pageview jumpto而不会解散用户的动画 /输入

玩心态 2025-02-01 01:23:12

您可以简单地使用:

df = pd.DataFrame(d['result']).T

或:

df = pd.DataFrame.from_dict(d['result'], orient='index')

输出:

             A   B   C  D
2011-12-01  53  28  32  0
2012-01-01  51  35  49  0
2012-02-01  63  32  56  0

You can simply use:

df = pd.DataFrame(d['result']).T

Or:

df = pd.DataFrame.from_dict(d['result'], orient='index')

Output:

             A   B   C  D
2011-12-01  53  28  32  0
2012-01-01  51  35  49  0
2012-02-01  63  32  56  0

将嵌套词典转换为Pandas DataFrame

玩心态 2025-01-31 14:08:22

您已经用 r python 标记了问题,因此尚不清楚您喜欢哪个。

您提供的材料列中只有19个唯一值,但是如果我们只采用前19种颜色,则可以在R中进行:

as.character(factor(Material, labels = colour[1:19]))
#>   [1] "#ad6e8d" "#ff7699" "#ff7699" "#ff7699" "#a5d32c" "#ecb2f8" "#ff7699"
#>   [8] "#ff7699" "#e45ee0" "#ff7699" "#ff7699" "#ff7699" "#6a4e0e" "#e45ee0"
#>  [15] "#ff7699" "#e45ee0" "#e45ee0" "#ff7699" "#e45ee0" "#ff7699" "#e45ee0"
#>  [22] "#ff7699" "#ff7699" "#e45ee0" "#e45ee0" "#ff7699" "#ff7699" "#ff7699"
#>  [29] "#59ab03" "#ff7699" "#ff7699" "#ad6e8d" "#ff7699" "#ff7699" "#e45ee0"
#>  [36] "#1f5392" "#e45ee0" "#ff7699" "#cbcb74" "#ff7699" "#6a4e0e" "#e45ee0"
#>  [43] "#ff7699" "#6a4e0e" "#e45ee0" "#ff7699" "#ecb2f8" "#ff7699" "#ff7699"
#>  [50] "#d6a0ff" "#ff7699" "#dd5609" "#dd5609" "#0079f1" "#ff7699" "#dd5609"
#>  [57] "#ff7699" "#e45ee0" "#e45ee0" "#903429" "#565485" "#ecb2f8" "#e45ee0"
#>  [64] "#01afe1" "#ff7699" "#59ab03" "#e45ee0" "#763c7c" "#e45ee0" "#ff7699"
#>  [71] "#e45ee0" "#ff7699" "#e45ee0" "#ff7699" "#ff7699" "#d6a0ff" "#e45ee0"
#>  [78] "#01a068" "#ff7699" "#e45ee0" "#ad6e8d" "#ff7699" "#6a4e0e" "#ad6e8d"
#>  [85] "#e45ee0" "#ff7699" "#763c7c" "#ff7699" "#e45ee0" "#e45ee0" "#96167c"
#>  [92] "#ff7699" "#0079f1" "#ff7699" "#ff7699" "#e45ee0" "#1f5392" "#ff7699"
#>  [99] "#0079f1" "#ff7699" "#ff7699" "#e45ee0" "#ff7699" "#e45ee0" "#e45ee0"
#> [106] "#ff7699" "#7bdc74" "#7bdc74 "

You have tagged your question with both r and python, so it's not clear which you prefer.

There are only 19 unique values in the Material column you provided, but if we take just the first 19 colours, in R we can do:

as.character(factor(Material, labels = colour[1:19]))
#>   [1] "#ad6e8d" "#ff7699" "#ff7699" "#ff7699" "#a5d32c" "#ecb2f8" "#ff7699"
#>   [8] "#ff7699" "#e45ee0" "#ff7699" "#ff7699" "#ff7699" "#6a4e0e" "#e45ee0"
#>  [15] "#ff7699" "#e45ee0" "#e45ee0" "#ff7699" "#e45ee0" "#ff7699" "#e45ee0"
#>  [22] "#ff7699" "#ff7699" "#e45ee0" "#e45ee0" "#ff7699" "#ff7699" "#ff7699"
#>  [29] "#59ab03" "#ff7699" "#ff7699" "#ad6e8d" "#ff7699" "#ff7699" "#e45ee0"
#>  [36] "#1f5392" "#e45ee0" "#ff7699" "#cbcb74" "#ff7699" "#6a4e0e" "#e45ee0"
#>  [43] "#ff7699" "#6a4e0e" "#e45ee0" "#ff7699" "#ecb2f8" "#ff7699" "#ff7699"
#>  [50] "#d6a0ff" "#ff7699" "#dd5609" "#dd5609" "#0079f1" "#ff7699" "#dd5609"
#>  [57] "#ff7699" "#e45ee0" "#e45ee0" "#903429" "#565485" "#ecb2f8" "#e45ee0"
#>  [64] "#01afe1" "#ff7699" "#59ab03" "#e45ee0" "#763c7c" "#e45ee0" "#ff7699"
#>  [71] "#e45ee0" "#ff7699" "#e45ee0" "#ff7699" "#ff7699" "#d6a0ff" "#e45ee0"
#>  [78] "#01a068" "#ff7699" "#e45ee0" "#ad6e8d" "#ff7699" "#6a4e0e" "#ad6e8d"
#>  [85] "#e45ee0" "#ff7699" "#763c7c" "#ff7699" "#e45ee0" "#e45ee0" "#96167c"
#>  [92] "#ff7699" "#0079f1" "#ff7699" "#ff7699" "#e45ee0" "#1f5392" "#ff7699"
#>  [99] "#0079f1" "#ff7699" "#ff7699" "#e45ee0" "#ff7699" "#e45ee0" "#e45ee0"
#> [106] "#ff7699" "#7bdc74" "#7bdc74 "

创建另一列颜色代码以分配另一列的值的命令是什么?

玩心态 2025-01-31 13:11:17

不是在Pycharm中,而是在VirSual Studio代码中,有和扩展称为

Not in pycharm but in Virsual Studio Code, there is and extension called CodeSnap, maybe just open your project from vscode then take clean screenshots of your code from there.

是否可以选择将Python文件保存到使用Pycharm的图像?

玩心态 2025-01-31 11:02:57

假设我们有一系列字符串,其中列出了所有数据库模式(可以通过应用程序属性进行预配置)。

我们可以根据架构名称过滤流,并为每个模式创建一个单独的JDBC接收器。

String[] schemas = {"schema-1", "schema-2", "schema-3"};

for(int i=0; i<schemas.length; i++){
    stream.filter(x -> x.schema.equals(schemas[i])).addSink(JdbcSink.sink(
                "insert into " + schemas[i] ".books (id, title, authors, year) values (?, ?, ?, ?)",
                (statement, book) -> {
                    statement.setLong(1, book.id);
                    statement.setString(2, book.title);
                    statement.setString(3, book.authors);
                    statement.setInt(4, book.year);
                },
                JdbcExecutionOptions.builder()
                        .withBatchSize(1000)
                        .withBatchIntervalMs(200)
                        .withMaxRetries(5)
                        .build(),
                new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
                        .withUrl("jdbc:postgresql://dbhost:5432/postgresdb")
                        .withDriverName("org.postgresql.Driver")
                        .withUsername("someUser")
                        .withPassword("somePassword")
                        .build()
        ));

}

Let's say that we have an array of Strings where all the database schemas are listed (can be pre-configured via application properties).

We can filter the stream based on the schema name and create an individual jdbc sink for each schema.

String[] schemas = {"schema-1", "schema-2", "schema-3"};

for(int i=0; i<schemas.length; i++){
    stream.filter(x -> x.schema.equals(schemas[i])).addSink(JdbcSink.sink(
                "insert into " + schemas[i] ".books (id, title, authors, year) values (?, ?, ?, ?)",
                (statement, book) -> {
                    statement.setLong(1, book.id);
                    statement.setString(2, book.title);
                    statement.setString(3, book.authors);
                    statement.setInt(4, book.year);
                },
                JdbcExecutionOptions.builder()
                        .withBatchSize(1000)
                        .withBatchIntervalMs(200)
                        .withMaxRetries(5)
                        .build(),
                new JdbcConnectionOptions.JdbcConnectionOptionsBuilder()
                        .withUrl("jdbc:postgresql://dbhost:5432/postgresdb")
                        .withDriverName("org.postgresql.Driver")
                        .withUsername("someUser")
                        .withPassword("somePassword")
                        .build()
        ));

}

Flink JDBC沉入多个模式

玩心态 2025-01-31 06:19:35

这是Heredoc,对于长字符串,您不必担心引用标记等。如果您注意到图表一词,然后有一行说图表;这表示字符串的末尾。

使用这种格式时要记住的重要事情是,无论您用来定义字符串末端的字符串(例如在这种情况下)角色可以在同一条线上的半分钟之后发生,甚至是空格,否则PHP认为这是字符串的一部分。

It's a heredoc, for long strings that you don't have to worry about quotation marks and whatnot. If you notice the word CHART and then there's a line that says CHART;, that indicates the end of the string.

The important thing to remember when using this format is that whatever string you use to define the end of the string (such as CHART in this case), that word has to appear on a line on its own, followed by a semicolon, and NO characters can occur after the semicolon on the same line, even whitespace, otherwise PHP thinks it's part of the string.

在PHP中,有什么作用。代表?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文